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

The given code aims to print all elements in the array 'arr', which is initialized with the...

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

The given code aims to print all elements in the array 'arr', which is initialized with the values {1, 2, 3, 4, 5}. However, there is an error in the code. Identify the error (if any) and fix it.

#include <stdio.h>

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    for (int i = 0; i <= 5; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}
Choose one option.
Show answer & explanation
Answer: A. A) Incorrect condition, Fix: Change "i <= 5" to "i < 5" in the for loop

Rigorous technical derivation based on engineering and aptitude principles.

Step-by-step Derivation:
Step 1: Analyze problem statement.
Step 2: Evaluate options.
Step 3: Select verified answer.