Simple printf with sizeof not working at all

I got the simplest code to display sizeof () data type, like int.

#include <stdio.h>
int main() { 
  printf('%i', sizeof(int));
}

No matter what I do, for example, putofof (int) as an integer, or use 'zu' instead of 'i', it passes me this error:

error: invalid conversion fromint’ to ‘const char*’

Is there something wrong with my compiler? I don’t understand why I can’t print so simple sizeof..

EDIT: It seems like printf('%s', 'foo');STILL is telling me what I'm converting intto const char*, how on earth ???

+5
source share
4 answers

Try print("%i", sizeof(int));

missing double quotes

Also research if you can use cstdio instead of stdio.h if you are in C ++.

+6
source

' ( int C), " ( " char" C).

printf :

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

, int, const char * -, const char *.

. ++ char, - " const char".

+8
printf("%zu", sizeof(int))
  • printf,
  • %zu, not %i ( , )
  • ,
+5

:

printf("%i\n", sizeof(int));

.

+1

All Articles