5
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

Animesh Kumar Paul
  • 2,241
  • 4
  • 26
  • 37

1 Answers1

6

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)).

user253751
  • 57,427
  • 7
  • 48
  • 90
  • Back in the very olden days, people used multibyte characters, like 'xy'. The PDP11 UNIX code had a lot of that stuff. It mostly went away when they ported C to bigendian machines. C++ fixed this ... character constants are chars. This is one of the few ways in which C is not a proper subset of C++. – Jim Balter Dec 23 '15 at 05:49