According to the official DSSSB 2021 answer key, which output was accepted for…
2021
According to the official DSSSB 2021 answer key, which output was accepted for the following C program?
void main()
{
int k, val = 1;
k = ++val * ++val;
printf("%d", k);
}Answer: C. 9 — ConceptIn standard C, the operands of * are not sequenced relative to each other. If two side effects on the same scalar object are unsequenced, the behavior…
- A.
1
- B.
4
- C.
9
- D.
16
Attempted by 938 students.
Show answer & explanation
Correct answer: C
Concept
In standard C, the operands of * are not sequenced relative to each other. If two side effects on the same scalar object are unsequenced, the behavior is undefined, so no compiler-independent numeric output can be derived from this expression. An exam-key lookup and a portable C-language analysis are therefore different tasks here.
Application
The statement
k = ++val * ++valmodifiesvalin both operands of one multiplication expression.Because those two modifications are unsequenced, standard C supplies no required output; a result observed with GCC or another compiler is only one manifestation of undefined behavior.
This question is anchored to the official DSSSB 2021 answer key. That key marks the value 9. Under the legacy exam convention used to obtain that value,
valis taken from 1 to 2 and then to 3 before both multiplication values are used, giving3 × 3 = 9.The learner’s three-term experiment,
++val * ++val * ++val, producing 36 instead of 64 does not refute a valid C rule: once the expression has undefined behavior, the compiler is not required to follow any repeatable “increment everything, then multiply” model.
Cross-check and exam procedure
The official DSSSB TGT Computer Science paper marks 9 for Question 111, so 9 is the accepted answer for this exact PYQ.
For a general C question, choose “undefined behavior” when it is offered, because that is the standards-based conclusion.
If a new question omits that choice and is not tied to a verified official key, do not infer a universal rule from one compiler run; treat the item as defective or request clarification.
Result: for this official-key-anchored DSSSB question, the accepted output is 9; as portable C code, the expression has undefined behavior.