Is "long x = 1/2" equal to 1 or 0, and why?

c, integer-division, java, long-integer

Solution

It's doing integer division, which truncates everything to the right of the decimal point.

Problem

if I have something like: ``` long x = 1/2; ``` shouldn't this be rounded up to 1? When I print it on the screen it say 0.

Original source

Related problems