Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the sizeof operator in C [duplicate]

Tags:

c

sizeof

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

Why the sizeof operator gives different output for same character? Please Help

like image 235
Animesh Kumar Paul Avatar asked Dec 23 '15 03:12

Animesh Kumar Paul


1 Answers

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 that. Its size is 4 bytes on your platform (the same as sizeof(1)).

like image 178
user253751 Avatar answered Oct 21 '22 04:10

user253751