Understanding the sizeof operator in C

char c = 'A'; printf("%d\n",sizeof(c));// output = 1 printf("%d\n",sizeof('A')); // output = 4 

Why does the sizeof operator give different output for a single character? Please, help

+5
source share
1 answer

c is a variable of type char ; its size is 1 byte.

'A' is an int literal - don't ask me why the standard says this. Its size is 4 bytes on your platform (same as sizeof(1) ).

+6
source

Source: https://habr.com/ru/post/1239004/


All Articles