I ran the following two codes on Windows XP (Code: Block, MinGW) and Ubuntu (11.04, g ++)
I am having trouble running the following code
This number is 2 ^ 63 -1. But I get an error message:
C: \ Documents and Settings \ JohnWong \ My Documents \ codeblock \ 343_hw_1 \ main.cpp | 9 | error: integer constant is also large for the "long" type |
On ubuntu - it compiled, but the retunred answer is 9223372036854775808, note 8 at the end ....
Now, if I run this code using the power function, I'm fine.
#include <iostream>
I will get the values I want (anything from +1 will lead to overflow, which is good).
On Ubuntu, the outputs look the same. Good.
So what is going on here? Why is a constant not good ??? I even tried intmax_t and int64_t as the data type that runs the first code.
Can someone explain this behavior? Thank you
c ++
Cppleearner
source share