

Hi Jayadithya,
Great question — this trips up a lot of learners.
The sizeof() operator does return the correct value — it gives you the size of a type or variable in bytes. But here’s the key part:printf() doesn’t know what type you're printing unless you tell it using a format specifier.
So even if sizeof(int) returns a valid number like 4, you still need to use %d or %lu (depending on your system and compiler) to tell printf how to interpret and display that value.
Now, about using different format specifiers — yes, that’s sometimes intentional. For example:
char ch = 'A';
printf("%d", ch); // Prints 65 instead of 'A'
Here, %d is used to show the numeric (ASCII) value of the character, not the character itself.
So to sum up:
sizeof()works fine — the issue is with how you choose to print the result.Sometimes, using a "wrong" format specifier is done on purpose to view data differently.
If you have more questions, I am here to help.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
