Array Assignment
Filed under Adobe
Free read 2 of 3Define the expression and identify the operations involved: array subscripting, assignment, and post-increment.
The question
Analyze the expression `array[i] = i++;` in C++ regarding undefined behavior due to unsequenced side effects.
Constraints
- Focus on C++ language standard rules regarding sequence points / modification and evaluation order.
- Assume standard variable declarations such as int i = 0; int array[10];
Examples
- Input
- int i = 0; int arr[5]; arr[i] = i++;
- Output
- Undefined Behavior
- Why
- The variable 'i' is both modified (via i++) and read (via array[i]) without a sequence point between them, resulting in undefined behavior according to the C++ standard.
Approach
Define the expression and identify the operations involved: array subscripting, assignment, and post-increment.
Explain that modifying 'i' and accessing 'i' in the same expression without a sequencing rule leads to undefined behavior.
Mention that prior to C++17, order of evaluation of operands of assignment was unspecified, and C++17 made it stricter but sequence rules still prohibit unsequenced modifications.
Show how to rewrite it safely: `array[i] = i; i++;`.
Tips
- What they are testing: Interviewers test your knowledge of low-level C++ standard semantics, evaluation order, and undefined behavior.
- Common mistake: Assuming left-to-right evaluation guarantees that array[i] is evaluated before i++ modifies i.
Related Adobe questions
Collected from public candidate posts and coding forums. Updated Nov 2026.