Kingwei 2005.3.10
Tutorial environment: Dev-C ++ 4.9.6.0 (gcc/mingw32), use the-Wall compilation Option
# Include <stdio. h>
Int main ()
{
Int v_int;
Signed int v_signed_int;
Unsigned int v_unsigned_int;
Signed short int v_signed_short_int;
Unsigned short int v_unsigned_short_int;
Signed long int v_signed_long_int;
Unsigned long int v_unsigned_long_int;
Freopen ("intuex.txt", "r", stdin );
Freopen ("out.txt", "w", stdout );
/* [-2 ^ 31, 2 ^ 31-1] ==> [-2147483648,214 7483647] */
Scanf ("% d", & v_int );
Printf ("% d/n", v_int );
/* [-2 ^ 31, 2 ^ 31-1] ==> [-2147483648,214 7483647] */
Scanf ("% d", & v_signed_int );
Printf ("% d/n", v_signed_int );
/* [0, 2 ^ 32-1] ==> [0, 4294967295] */
Scanf ("% u", & v_unsigned_int );
Printf ("% u/n", v_unsigned_int );
/* [-2 ^ 15, 2 ^ 15-1] => [-32768,327 67] */
Scanf ("% hd", & v_signed_short_int );
Printf ("% hd/n", v_signed_short_int );
/* [0, 2 ^ 32-1] ==> [0, 65535] */
Scanf ("% hu", & v_unsigned_short_int );
Printf ("% hu/n", v_unsigned_short_int );
/* [-2 ^ 31, 2 ^ 31-1] ==> [-2147483648,214 7483647] */
Scanf ("% ld", & v_signed_long_int );
Printf ("% ld/n", v_signed_long_int );
/* [0, 2 ^ 32-1] ==> [0, 4294967295] */
Scanf ("% lu", & v_unsigned_long_int );
Printf ("% lu/N", v_unsigned_long_int );
Return 0;
}
Test example and output:
----- Test case #1: Lower Bound -----
-2147483648
-2147483648
0
-32768
0
-2147483648
0
Output:
-2147483648
-2147483648
0
-32768
0
-2147483648
0
----- Test case #2: Upper Bound -----
2147483647
2147483647
4294967295
32767
65535
2147483647
4294967295
Output:
2147483647
2147483647
4294967295
32767
65535
2147483647
4294967295
----- Test case #3: underflow -----
-2147483649
-2147483649
-1
-32769
-1
-2147483649
-1
Output:
2147483647
2147483647
4294967295
32767
65535
2147483647
4294967295
----- Test case #4: overflow -----
2147483648
2147483648
4294967296
32768
65536
2147483648
4294967296
Output:
-2147483648
-2147483648
0
-32768
0
-2147483648
0
As you can see, the input data overflows to form the upper bound of the range that can be expressed by this type. The input data overflows to form the lower bound of the range that this type can represent.