(A)
2 3 5 6
(B)
2 3 4 5
(C)
4 5 0 0
(D)
none of the above
Answer: (A)
Explanation:
In the above code, we have declared: int a[][3] = {1, 2, 3, 4, 5, 6};
This line declares a 2D array with 2 rows and 3 columns. The elements are initialized in row-major order: 1, 2, and 3 are the elements of the first row, and 4, 5, and 6 are the elements of the second row.
int (*ptr)[3] = a; This line declares a pointer to an array of 3 integers and assigns it the address of the first row of the array a. The pointer ptr now points to the first row of a.
printf(“%d %d “, (*ptr)[1], (*ptr)[2]); his line prints the a[0][1]and a[0][2] elements of the first row of a, which are 2 and 3, respectively. So the output of this line is “2 3 “.
++ptr; This line increments the pointer ptr, causing it to point to the second row of a.
printf(“%d %d\n”, (*ptr)[1], (*ptr)[2]); This line prints the second and third elements of the second row of a, which are 5 and 6, respectively. The final output is “2 3 5 6″.
Hence the correct answer is (A).
Quiz of this Question
Please comment below if you find anything wrong in the above post
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
28 Jun, 2021
Like Article
Save Article