TL;DR answer:
sizeof result
is same as sizeof(char)
.
sizeof(num1+ num2)
is same as sizeof (int)
why?
In your case, they produce 1 (guaranteed by standard) and 4 (may vary), respectively.
That said, sizeof
produces a result of type size_t
, so you should %zu
format specifier to print the value.
Why:
First, for the addition operator +
, quoting C11
, chapter §6.5.6
If both operands have arithmetic type, the usual arithmetic conversions are performed on
them.
Regarding usual arithmetic conversions, §6.3.1.8/p1
[....] Otherwise, the integer promotions are performed on both operands.[...]
and then from §6.3.1.1,/p2,
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.
So, sizeof(num1+num2)
is the same as sizeof(int)
.