1. 程式人生 > >Dev-C++下關於幾種int型別格式符的實驗

Dev-C++下關於幾種int型別格式符的實驗

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);