Char type C size

Possible duplicate:
Why are characters characters characters C characters instead of characters?

people,

I tried to print the char size in C. Using the following code, I got the result as

int, 4 char, 1 char?, 4 

Why does the latter not coincide with the second? Thanks.

 #include <stdio.h> main() { int a = 2; char b = '2'; printf("int, %d\n",sizeof(a)); printf("char, %d\n",sizeof(b)); printf("char?, %d\n",sizeof('a')); } 
+6
source share
1 answer

In C, a character constant of type 'a' is of type int .

This is different from C ++ and Java, where the character constant of type 'a' is of type char ,

+24
source

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


All Articles