How does sizeof work for different data types when added and calculated? [duplicate]
This question already has answers here : Closed 5 years ago . What happens here? sizeof(short_int_variable + char_variable) (5 answers) #include <stdio.h> int main() { short int i = 20; char c = 97; printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i)); return 0; } The output of this code is 2, 1, 4 According to me it should be 2, 1, 2 because char + short int is short int and size of short int is 2 . According to C standard integral promotion rules , the type of the expression c + i will be int , that's why you're getting the equivalent of sizeof (int) , i.e. 4 . When different