Which of the following statements about sizeof and expressions in C is correct?

Options

  • A. sizeof(x++) normally does not increment x
  • B. sizeof always returns the value of the expression
  • C. sizeof can only be used with variables and not data types
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. sizeof(x++) normally does not increment x

Detailed Explanation

Correct Answer: sizeof(x++) normally does not increment x.

The sizeof operator determines the size of the type of its operand. When the operand is an expression whose evaluation is not required, the expression is not evaluated.

For example, if x = 5, then sizeof(x++) returns the size of an integer but does not perform the increment. Therefore x remains 5.

Also, sizeof can be used with both expressions and data types. For example, sizeof(int) is valid.

BPSC exam point: The most important trick is remembering that side effects such as incrementing a variable generally do not occur when the expression is unevaluated inside sizeof.