What is the output of the following code snippet? #include <stdio.h> #define…

2018

What is the output of the following code snippet? #include <stdio.h> #define var 3 void main() { short num[3][2] = {3, 6, 9, 12, 15, 18}; printf("%d %d", * (num+1)[1], * *(num+2)); }

  1. A.

    12 15

  2. B.

    15 12

  3. C.

    15 15

  4. D.

    12 12

Attempted by 141 students.

Show answer & explanation

Correct answer: C

num is a 2D array:

Row

Elements

num[0]

3 6

num[1]

9 12

num[2]

15 18

  • *(num+1)[1]
    num + 1 → points to num[1]{9, 12}
    (num+1)[1] → same as *(num+1 + 1)num[2]{15, 18}
    *(num+1)[1] → first element of num[2]15

  • **(num+2)
    num + 2 → points to num[2]{15, 18}
    *(num+2) → points to first element → 15
    **(num+2) → value → 15

  • Final Output: 15 15

Explore the full course: Up Lt Grade Assistant Teacher 2025