What will be the output of the following C program?

#include <stdio.h>

int main()
{
int a = 10, b = 20;

```
printf("%d", sizeof(a + b));

return 0;
```

}
                        

Options

  • A. 2
  • B. 4
  • C. 30
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 4

Detailed Explanation

Correct Answer: 4

The expression a + b has an integer type because both a and b are integers.

The value of the expression is 30, but sizeof does not return that value. It returns the size of the expression's type.

Since the expression has type int and an integer occupies 4 bytes under the assumption, sizeof(a+b) returns 4.

Exam trick: Do not confuse the value of an expression with the size of its data type.