#include <stdio.h>
int main()
{
unsigned char c = 'a';
c = c + 3;
printf("%c ", c);
printf("%zu",sizeof(c));
return 0;
}
Output:d 1
when integer promotion takes place implicitly in c. then why the size of char is printing 1(in bytes) rather 4(in bytes), since the size should increase to 32bits right?
Iam thinking that the output shall be: d 4
It's correct that the calculation of
c + 3involves integer promotion, i.e. the type of the result isint. However, when you store that result in yourcharvariable usingc = ...it will be converted back to acharagain. The assignment will not (can not) change the size of your variable.Try this code:
On my system it gives: