An integer in C int is represented by 4 bytes 1 byte 8 bits
An integer in C (int) is represented by 4 bytes (1 byte = 8 bits). Find the largest integer that can be handled by C. Verify that number by computer (try to printf that number, and printf that number+1). No programming is required for this.
Solution
In C size of int
Min: -2147483648
Max: 2147483647
So for your first question Find the largest integer that can be handled by C
Answer would be 2147483647
You can verify by the value by Executing below line of code
#include <stdio.h>
#include <limits.h>
int main()
{
printf(\"The minimum value of INT = %d\ \", INT_MIN);//it will print -2147483648
printf(\"The maximum value of INT = %d\ \", INT_MAX);//it will print 2147483647
return(0);
}
now come back to your next question printf that number+1
printf(\"The maximum value of INT = %d\ \", INT_MAX+1);//it will print -2147483648(may depend it may also crash)
above line may print you the -2147483648 , yes min value of int or some times program can crash.
Reason:this operation invokes undefined behavior. Signed integer overflow is undefined behavior in C.
For best practise Do not let portable program compute this expression.
Output:
The minimum value of INT = -2147483648
The maximum value of INT = 2147483647
The maximum value of INT+1 = -2147483648
--------------------------------
Process exited after 0.3287 seconds with return value 0
Press any key to continue . . .
