Each solid in the c/c+ (every literal) has a type, for example, 10 is an int, so SIZIOF (10) and sizeof (int) are the same, but the character-solid (' a ') has different variable types in C and C + +.
In C, ' a ' is considered int, and in C + +, ' a ' is considered to be a char type.
int Main () { printf("sizeof (' V ') =%d sizeof (char) =%d"sizeof(' V'sizeof(char)); return 0 ;}
Results:
C result– sizeof (' V ') = 4 sizeof (char) = 1
C + + result– sizeof (' V ') = 1 sizeof (char) = 1
The above behavior can also reflect C + + function overloading
void foo (char c) {printf ( from Foo:char " void foo (int i) {printf ( from foo:int " );} int main () {foo ( '
Then call void foo (char c)
3) Types of Boolean results is different in C and C + +.
// output = 4 in C (which is size of int)printf ("%d"sizeof(1= =1< /c8>// output = 1 in C + + (which is the size of the Boolean datatype)sizeof(1==1
[C/cpp Series knowledge] Type difference of character literals and bool in C and C + +