Sadek Sadek - 24 days ago 7
C Question

Why 'l' and 'll' modifier do the same for printf (C)

I don't understand the difference between

l
and
ll
length specifier for the printf function :

printf("%ld \n", 9999999991474836499);
printf("%lld \n", 9999999991474836499);


The two printf make the same output because to the type overflow:

-8446744082234715117
-8446744082234715117


So when I remove one digit I do :

printf("%ld \n", 999999999147483649);
printf("%lld \n", 999999999147483649);


And I get the same output :

999999999147483649
999999999147483649


Without overflow.

I don't understand
l
mean
long int
and
ll
mean
long long int
so why they aren't any difference?

Answer

On some computers, long and long long have the same representation, so ll and l do the same thing. This is true for most 64-bit platforms, except Windows. (This is an explanation of why it worked that way, not a promise that it must work that way.)

On other platforms—64-bit Windows, 32-bit anything, you will not be so lucky.

The program is incorrect either way, it just happened to work by chance, and there is no guarantee that it will continue to work, even on the same platform.