Skip to content
Related Articles

Related Articles

C Quiz – 102 | Question 5

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Easy
  • Last Updated : 28 Jun, 2021

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.


Answer:

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!