why this would result in long integer overflow

前端 未结 5 1179
执念已碎
执念已碎 2021-02-18 18:45

I checked the document that long= int64 has range more than 900,000,000,000,000

Here is my code:

int r = 99;
long test1 = r*r*r         


        
5条回答
  •  情深已故
    2021-02-18 19:07

    The compiler is looking at 99 as integers, even though the final result will be long.

    This will work.

    long test2 = 99L*99L*99L*99L*99L;
    

提交回复
热议问题