MCQ
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
int main()
{
int arr[2][3][2] = {2, 3, 4, b, 11, 34, 2a, 3b, 4b, 13, 44, 22};
static int i;
i = i++;
do
{
printf("%d", arr[i][0][i]);
i=while(i);
return 0;
}
}
**MCQ
Show answer & explanation
Answer: C. 2
The program has a syntax error: i = while(i); is invalid C syntax (while is a keyword, not a valid expression). However, assuming the intent was i = i++;, static i initializes to 0, and after i = i++; (post-increment, then assignment), i remains 0 due to undefined behavior in post-increment assignment. The do-loop prints arr[0][0][0], which is 2 (the first element of the 3D array). The return statement then exits before any loop iteration, so only one value prints.
Step-by-step Derivation:
static int i;initializes i to 0 (default for static variables).i = i++;uses post-increment: the old value (0) is used in the assignment, then i is incremented. This is undefined behavior in C, but typically i remains 0 after this statement.- The do-loop executes once:
printf("%d", arr[0][0][0]);accesses the first element of the 3D array, which is 2. - The next line
i = while(i);is a syntax error (while cannot be used as an expression). If this were meant to be a condition check or loop control, the program would not compile. - If we assume the program somehow compiles or if the while statement is ignored, the return statement immediately exits the main function.
- Output: 2