+ 1
Why does sizeof() in C requires %ld as format specifier instead of just %d?
https://code.sololearn.com/c0vYc9d5SDyV/?ref=app Here in this program, why do I have to give %ld instead of just %d? Why do I get errors when I use %d?
2 Réponses
+ 6
You don't get errors when you give %d but get a warning.
The size of() function expects a long unsigned int type but when you give %d it's only int type. When you write, %ld it means long int . It works without any error.
But the best one is:
%lu
Because using %lu means long unsigned int which is the type of specifier that sizeof() use.
You can have a look at this question:
https://stackoverflow.com/questions/21128092/d-expects-argument-of-type-int-but-argument-2-has-type-long-unsigned-int
+ 1
The future is now thanks to science[LESS ACTIVE] Thanks, that was really helpful