sizeof operator returns 4 for (char + short )

c

Solution

`c + i` is an integer expression (integer promotion!), so `sizeof()` returns `sizeof(int)`

Problem

Given this code snippet: ``` #include <stdio.h> int main() { short i = 20; char c = 97; printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i)); return 0; } ``` Why is `sizeof(c + i) == 4`?

Original source

Related problems