A tricky question

After executing the following instruction:

long time = 60 * 1000000000; // 60 seconds in nano-second units

What will be the value of the variable time ?

Your doing:

long x = (long)(int*int);

Do:

long x = long * long;

To prevent overflow of your ints

I was expecting a newbie to fall for it. ;D

Anyway you are absolutly right. This is what i used:

long time = 60L * 1000000000L;

But just as a curiosity C++ also messes up with our intuition on this one.

Oh crap, I better go change my code then :slight_smile:

well the 2nd number defaults to Long doesn’t it? :-*

1000000000 = fits perfectly in 32 bits
4294967296 = max for unsigned 32 bits
2147483647 = max for signed 32 bits

And long values never default to long.

6000000000 = invalid, compile-time error
6000000000L = valid

ah yes, horray for compile time checking.