Hi all - I am having some difficulty displaying a variable of type 'long long' with printf(). My code is as follows:
This compiles with no warnings for me (mingw gcc 3.4.2). However, the output I recieve is always this:
/* File: largenum.c */
int main(int argc, char *argv)
// note that the last two characters are lowercase 'L', not '1'
long long num = 317584931803ll;
printf("Very Large Number: %lld \n", num );
printf("Sizeof (long long) = %d\n", sizeof(long long) );
If I convert the project to c++ and use cout to display num, it shows exactly the number I want it to, but I already am quite familiar with C++, and I want to learn how to do this in C.
Very Large Number: -242648101
Sizeof (long long) = 8
The size of a long long is 8 bytes (as it should be), so I am fairly certain that the problem lies in my usage of printf(). If I convert it to an 'unsigned long long', and printf("%llu ", num) -- , I at least get a POSITIVE number, but it is still not the correct number. Any help would be appreciated.