Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - The calculation is incorrect when the addition number of C language is large.
The calculation is incorrect when the addition number of C language is large.
Int is plastic data with a range of values (depending on the structure of compiler and computer system). At present, mainstream compilers set the value range of integer types between -2 147483648 and 2 14748367 (in fact, it is a power of 2, that is, 3 1, so positive integers are missing). This leads to the operation of shaping data is not closed, and the value of operation will exceed the limit, resulting in an operation error (this phenomenon is called "integer overflow"). So this situation is normal, but it should be avoided as much as possible when programming.

To add and subtract, just declare an int variable dif and insert it.

dif = a-b;

Printf ("difference is %d\n", dif);

Just do it, as follows:

Master ()

{

int a,b,sum,dif

Scanf("%d%d ",&i, & b);

sum = a+b;

dif = a-b;

Printf("sum is %d\n ",sum);

Printf ("difference is %d\n", dif);

system(" pause \ n ");

}

In general, if you only write int, it is equal to long int (that is, int), and you don't need to change it. It can only be in this range.

In addition, -32768 to 32767(2 to the power of 15) in the answer is the range of short int (short can also be written).