I just found this code on Wikipedia.
Link: http://en.wikipedia.org/wiki/Sizeof#Use
The code:
/* the following code illustrates the use of sizeof
* with variables and expressions (no parentheses needed),
* and with type names (parentheses needed)
*/
char c;
printf("%zu,%zu", sizeof c, sizeof(int));
It states that: "The z prefix should be used to print it, because the actual size can differ on each architecture."
I tried it on my compiler, but it gives the following result:
zu,zu
%lu
and explicitly cast thesizeof
value tounsigned long
- as long as you know that the size of the object is less than 4GB you know then that it will definitely be reported correctly. – Shahjahanpur