+ 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?

3rd Jul 2021, 7:07 AM
Srinath
2 Antworten
+ 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
3rd Jul 2021, 7:35 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
The future is now thanks to science[LESS ACTIVE] Thanks, that was really helpful
3rd Jul 2021, 7:59 AM
Srinath