Experiment on several types of int format operators in Dev-C ++

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.