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)); }
- A.
12 15
- B.
15 12
- C.
15 15
- 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 tonum[1]→{9, 12}(num+1)[1]→ same as*(num+1 + 1)→num[2]→{15, 18}*(num+1)[1]→ first element ofnum[2]→15**(num+2)
num + 2→ points tonum[2]→{15, 18}*(num+2)→ points to first element →15**(num+2)→ value →15Final Output: 15 15