Bird
0
0

What will be the output of this C program?

medium📝 Predict Output Q5 of 15
C - Basics and Execution Environment
What will be the output of this C program?
int main() {
    int arr[3] = {1, 2, 3};
    int *p = arr;
    printf("%d", *(p + 2));
    return 0;
}
A1
BCompilation error
C2
D3
Step-by-Step Solution
Solution:
  1. Step 1: Understand pointer arithmetic

    Pointer p points to arr[0]. Adding 2 moves to arr[2].
  2. Step 2: Access the value at arr[2]

    arr[2] is 3, so *(p + 2) is 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Pointer arithmetic accesses arr[2] = 3 [OK]
Quick Trick: Pointer + index accesses array element at that index [OK]
Common Mistakes:
  • Confusing pointer arithmetic with array indexing
  • Assuming *(p + 2) is arr[0]
  • Expecting compilation error due to pointer use

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes