Multiplying int with long result c#

后端 未结 6 1598
自闭症患者
自闭症患者 2020-12-18 07:29

Wonder why. C# .Net 3.5

int a = 256 * 1024 * 1024;
int b = 8;
long c = b * a;
Console.WriteLine(c);//<-- result is -2147483648 

Where do

6条回答
  •  情话喂你
    2020-12-18 07:59

    Because b * a is already overflowed integer, before it is assigned to the long data type variable.

提交回复
热议问题