Comment afficher la valeur maximale d'un long non signé en C?

Ce que je fais mal?

$ cat size.c
#include<stdio.h>
#include<math.h>

int main() {

printf ("sizeof unsigned int = %d bytes.\n", sizeof(unsigned int));
printf ("sizeof unsigned long long = %d bytes.\n", sizeof(unsigned long long));

printf ("max unsigned int = %d\n", (int)(pow(2, 32) - 1));
printf ("max unsigned long long = %lld\n", (unsigned long long)(pow(2, 64) - 1));

}
$ gcc size.c -o size
$ ./size
sizeof unsigned int = 4 bytes.
sizeof unsigned long long = 8 bytes.
max unsigned int = 2147483647
max unsigned long long = -1
$ 

Je suis dans l'attente d' 18446744073709551615 en sortie au lieu d'une -1 à la dernière ligne.


Bon, je l'ai complètement oubliée que j'avais la mauvaise valeur pour la 232 - 1, ce qui devrait avoir été 4294967295, pas de 2 147 483 647. Les choses prennent plus de sens maintenant.

source d'informationauteur Lazer