+ 1

Why is the output 2?

#include<stdio.h> int main() { int a[3] ={2,1,0}; printf("%d",a[a[2]]); }

12th May 2021, 6:55 AM
Hridoy Banik
6 Answers
+ 4
a[2]=0,and a[0]=2
12th May 2021, 6:56 AM
Atul [Inactive]
+ 2
Divide the question into simpler terms and go step by step
12th May 2021, 6:57 AM
Atul [Inactive]
+ 2
See printf("%d",a[a[2]]); Here a[2] will be calculated first because it is present inside . After calculation answer=0(a[2]). Now the value of a[0] =2
12th May 2021, 7:00 AM
Atul [Inactive]
0
Sorry Can you elaborate ?
12th May 2021, 6:57 AM
Hridoy Banik
0
Thanks mate Got it!!
12th May 2021, 6:58 AM
Hridoy Banik
0
Hridoy Banik My pleasure
12th May 2021, 7:00 AM
Atul [Inactive]