Kingwei 2005.3.10
Experimental environment: DEV-C 4.9.6.0 (GCC / MINGW32), use -wall compile options
#include
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, 2147483647] * / scanf ("% d", & v_int) PRINTF ("% d / n", v_int); / * [-2 ^ 31, 2 ^ 31-1] ==> [-2147483648, 2147483647] * / 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, 32767] * / 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, 2147483647] * / 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 samples and output:
----- Test Case # 1: Down -----
-2147483648-21474836480-327680-21474836480
OUTPUT:
-2147483648-21474836480-327680-21474836480
----- Test Case # 2: Upload -----
214748364721474836474294967295327676553521474836474294967295
OUTPUT:
214748364721474836474294967295327676553521474836474294967295
----- Test Case # 3: Upperflow ------ 2147483649-2147483649-1-32769-1-2147483649-1
OUTPUT:
214748364721474836474294967295327676553521474836474294967295
----- Test Case # 4: overflow -----
214748364821474836484294967296327686553621474836484294967296
OUTPUT:
-2147483648-21474836480-327680-21474836480
It can be seen that the input data is overflow, which is the upper bound that can represent the range of the range; the input data overflow is the lower bound of the range that can represent the range.