OA. free
Free
MathWorks Core Computer Science Core Computer Science Medium

What is the output of the following code snippet: Pick ONE option

MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.

What is the output of the following code snippet:

#include <iostream>
int main()
{
    int arr[5] = {11,22,33,44,55};
    for(int i = 0; i < 5; i++)
        cout<<*(arr+i)<<" ";
    return 0;
}

Pick ONE option

Choose one option.
Show answer & explanation
Answer: C. 11 22 33 44 55

The expression *(arr+i) dereferences the pointer arithmetic result. arr+i points to the element at index i, and dereferencing it with * retrieves that element's value. The loop iterates from i=0 to i=4, printing each array element followed by a space: 11, 22, 33, 44, 55.

Step-by-step Derivation:
Iteration trace:

  • i=0: *(arr+0) = arr[0] = 11
  • i=1: *(arr+1) = arr[1] = 22
  • i=2: *(arr+2) = arr[2] = 33
  • i=3: *(arr+3) = arr[3] = 44
  • i=4: *(arr+4) = arr[4] = 55

Output: 11 22 33 44 55 (with trailing space)

Note: Option A incorrectly increments by 1 and adds an offset (not how array indexing works). Option B skips the first element. Option D would only occur if the array were uninitialized.