why this would result in long integer overflow

前端 未结 5 1197
执念已碎
执念已碎 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:14

    Your second test fails because each 99 is an integer; replace it with the following and it compiles.

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

    See the MSDN Long Documentation for details.

提交回复
热议问题