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')); }
In C, a character constant of type 'a' is of type int .
'a'
int
This is different from C ++ and Java, where the character constant of type 'a' is of type char ,
char
Source: https://habr.com/ru/post/909894/More articles:User Agent String for IPhone 4S - iphonewhich is faster? Statement or prepared expression - java"Lock screen" with user security password - androidSSLHandshakeException: no common cipher suites - javaAdd / remove item to array in Amazon DynamoDB - javaUsing Less css framework in production - javaInitializing an instance variable in Ruby - ruby | fooobar.comAccessing XAML Controls from C # Code - c #Doctrine 2 - persistent error - Warning: spl_object_hash () expects parameter 1 to be an object, null - zend-frameworkOptimization of vectorized code for graph adjacency - optimizationAll Articles