I'm a newbie to C programming and I've found this strange behaviour while using the following placeholders specification in the function printf
's argument. I get two different results while using an online C compiler (OnlineGDB) and VSCode with gcc terminal compilation.
That's the snippet:
#include <stdio.h>
int main()
{
printf("%lld", 4);
return 0;
}
As Wiki says, "the ll lenght field placeholder is made for integer types, and causes printf to expect a long long-sized integer argument". In the online Compiler I get this:
main.c:13:16: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat= ]
4
So it prints 4 after a warning.
The result in VSCode is completely different :
15621861207441412
No warnings but where's that number coming from?
Why is there such a different behaviour in such a "simple" situation? Isn't the value 4 also an ll-integer? My guess is that the second one expects a bigger value so it sends me a quite a random value in that interval. Also, I have to study C for a college exam, could you recommend which compiler should I use in compiling sample projects? Thanks a lot for you time.