For starters this call
printf("%d,%d,%d",sizeof(i),sizeof(c),sizeof(c+i));
has undefined behavior because there are used incorrect format specifiers.
It should look like
printf("%zu,%zu,%zu",sizeof(i),sizeof(c),sizeof(c+i));
because the type of the value evaluated by the sizeof
operator is size_t
.
Due to the integer promotions (as a part of the usual arithmetic conversions) the expression c + i
has the type int
.
From the C Standard (6.3.1 Arithmetic operands)
- ...If an int can represent all values of the original type (as restricted
by the width, for a bit-field), the value is converted to
an int; otherwise, it is converted to an unsigned int. These are
called the integer promotions.58) All other types are unchanged by
the integer promotions.
and (6.5.6 Additive operators)
4 If both operands have arithmetic type, the usual arithmetic
conversions are performed on them.
Thus if the size of object of the type int
is equal to 4
then the expression sizeof(c+i)
yields 4
.