Simple printf with sizeof does not work at all

Try printf("%zu", sizeof(int));

The double quotes are missing.

Also explore if you can use cstdio instead of stdio.h if you are on C++.


printf("%zu", sizeof(int));
  • printf, not print
  • double quotes, not single quotes
  • %zu, not %i (because sizeof returns an unsigned value, not an integer)

Single quotes ' are used to delimit character literals (type int in C) while double quotes " are used to delimit string literals (type "array of char" in C).

printf is declared as follows:

int printf (const char * format, ...)

Thus you are attempting to pass an int where the function expects a const char * or something that can be converted to const char *.

Note: In C++ character literals are type char, string literals are "array of const char".

Tags:

C

Sizeof