Hi all - I am having some difficulty displaying a variable of type 'long long' with printf(). My code is as follows:
Code:
/* File: largenum.c */
#include <stdio.h>
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) );
return 0;
}
This compiles with no warnings for me (mingw gcc 3.4.2). However, the output I recieve is always this:
Very Large Number: -242648101
Sizeof (long long) = 8
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.
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.