Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - # include & ltstdio.h & gtMain() { Short int n=0x7fff,m = n+ 1; Printf("%d,%d\n ",n,m); What is the answer?
# include & ltstdio.h & gtMain() { Short int n=0x7fff,m = n+ 1; Printf("%d,%d\n ",n,m); What is the answer?
At present, in most compilers, the size of short int is 2 bytes. Because the number of symbols in a computer is represented by complement, 0x7fff is exactly the largest positive number it can represent, m=n+ 1, so m=0x8000, which is a negative number -32768.

When passing function parameters, the types of char and short are automatically upgraded to integers. When the compiler converts n and m into integers, it finds that the sign bit of m is 1, so it will expand the sign and get the integer -32768. Therefore, when using %d format controller to interpret these two parameters, you will get 32767 and -32768 respectively.