This is an implementation defined as earlier answers already say.
My gcc treats 'ab' as an int. The following code:
printf( "sizeof('ab') = %zu \n", sizeof('ab') );
printf( "'ab' = 0x%08x \n", 'ab' );
printf( "'abc' = 0x%08x \n", 'abc' );
prints:
sizeof('ab') = 4
'ab' = 0x00006162
'abc' = 0x00616263
In your code, the line:
char c = 'ab';
It can be considered as:
char c = (char)(0x00006162 & 0xFF);
So c gets the value of the last char from 'ab'. In this case, it is "b" (0x62).
source
share