Assume size of an integer as 4 bytes. What is the output of the above program?
#include <stdio.h>
int main()
{
int i = 5, j = 10, k = 15;
```
printf("%d ", sizeof(k /= i + j));
printf("%d", k);
return 0;
```
}
Options
-
A.
2 1
-
B.
4 1
-
C.
4 15
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
C.
4 15
Detailed Explanation
Correct Answer: 4 15
The important concept in this question is the sizeof operator.
The expression inside sizeof is k /= i + j. Normally, this expression would perform an assignment operation. However, when an expression is used as the operand of sizeof, the expression is generally not evaluated.
Therefore, k /= i + j does not actually execute, so the value of k remains 15.
The expression has type int, and the question states that an integer occupies 4 bytes. Therefore:
sizeof(k /= i + j) = 4
The first printf prints 4 and the second printf prints the unchanged value of k = 15.
Therefore, the output is 4 15.
Exam trick: Remember that sizeof usually determines the size without evaluating its operand.