Ask your own question, for FREE!
Computer Science 4 Online
OpenStudy (anonymous):

in C lets say I declare long long x = 123456789012345 and then I do x / pow(10, 13) == 12 This evaluates to false rather than the expected true. What am I missing?

OpenStudy (anonymous):

it does work however if I do int y = x / pow(10, 13) and then y == 12 This does evaluate to true

OpenStudy (anonymous):

I know this is a bit late, but it might be useful to know. In your code: long long x = 123456789012345 The right side of the expression is evaluated by the compiler as an integer before it is assigned to the long, meaning the value overflows. This is why the second check works but not the first. To make the compiler interpret the value as a long, you need to specify that with a capital L, like so: long x = 123456789012345L or long long x = 123456789012345LL

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!