CodePudding user response:
90625 square is too big, the overflowCodePudding user response:
The 90625 is also defined as a long long, or coercion (long long) 90625CodePudding user response:
90625 first is int type, that is to say before the assignment for squ, these are the two type int is multiplied by the data, so there will be overflow,So suggest so write squ=(long long) 90625 * 90625;
Makes the expression on the right to use long long type, it can get normal results
CodePudding user response:
Have a look at the disassembly code may be more clearlysqu=90625 * 90625;
Corresponding to the disassembly code is
008018 be mov dword PTR [squ], 0 e986c401h
008018 c5 mov dword PTR [ebp - 8], 0 FFFFFFFFH
As you can see, 90625 * 90625 x1e986c401 values should be 0, the first line of the assembly instruction role is to put the 4 bytes 0 x1e986c401 low namely 0 squ xe986c401 values in the low 4 bytes, because the highest E is 1, so the second line assembly instruction put 0 XFFFFFFFF as a supplement to squ high 4 bytes, the squ a value of 0 xffffffffe986c401
And if the C code is
squ=(long long) 90625 * 90625;
At this point the corresponding assembly instruction is
005518 be mov dword PTR [squ], 0 e986c401h
005518 c5 mov dword PTR [ebp - 8], 1
The first line the assembly code did not change, is to put the 0 x1e986c401 extra 1 copy to squ low 4 bytes, namely the value is 0 x00000001e986c401 squ
CodePudding user response:
Thanks for brother