Open In App
Related Articles

C Quiz – 102 | Question 5

Improve Article
Save Article
Like Article

In the context of the below program snippet, pick the best answer.

#include "stdio.h"
int arr[10][10][10];
int main()
 arr[5][5][5] = 123;
 return 0;

Which of the given printf statement(s) would be able to print arr[5][5][5]

(i) printf("%d",arr[5][5][5]);
(ii) printf("%d",*(*(*(arr+5)+5)+5));
(iii) printf("%d",(*(*(arr+5)+5))[5]);
(iv) printf("%d",*((*(arr+5))[5]+5));

(A) only (i) would compile and print 123.
(B) both (i) and (ii) would compile and both would print 123.
(C) only (i), (ii) and (iii) would compile but only (i) and (ii) would print 123.
(D) only (i), (ii) and (iii) would compile and all three would print 123.
(E) all (i), (ii), (iii) and (iv) would compile but only (i) and (ii) would print 123.
all (i), (ii), (iii) and (iv) would compile and all would print 123.


Explanation: For arrays, we can convert array subscript operator [] to pointer deference operator * with proper offset. It means that arr[x] is equal to *(arr+x). Basically, these two are interchangeable. The same concept can be applied in multi-dimensional arrays as well.

That’s why all of the above 4 printf are referring to the same element i.e. arr[5][5][5]

Quiz of this Question

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
Similar Reads