+ 5

/*Please explain the output, output is 12 11 1*/

#include <stdio.h> int main() { int a[5]={5,10,15,20,25}; int i,j,k=1,m; i=++a[1]; j=a[1]++; m=a[i++]; printf ("\n%d %d %d",i,j,m); return 0; }

16th Apr 2018, 11:47 AM
Nitesh Yadav
Nitesh Yadav - avatar
12 Antworten
+ 2
i = 1, ++1 makes 2, 2 + a[1] equals 12 j = a[1] ++ makes 10 + 1 equals 11 m= a[13] , this is out if bound so the initialen value 1 is printed Would expert a out of bound exception, do not know why that's is geen as valide.
16th Apr 2018, 12:02 PM
sneeze
sneeze - avatar
+ 2
you mean i=[++a1] is not initialization? and i still==0 after that, right?
17th Apr 2018, 8:50 PM
Sergey Semendyaev
Sergey Semendyaev - avatar
+ 1
@~ swim ~ I have to admit you are right. Thanks for pointing it out.
17th Apr 2018, 8:06 PM
sneeze
sneeze - avatar
+ 1
so I don't get one thing. why is m == 1 in the end if m = a[i++] and i = 11? is it realy random?
17th Apr 2018, 9:06 PM
Sergey Semendyaev
Sergey Semendyaev - avatar
+ 1
thank you)
17th Apr 2018, 9:46 PM
Sergey Semendyaev
Sergey Semendyaev - avatar