Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

a[]={0,1,2,3,4,5,6,7,8,9,10}; i=0; a[i]=a[++i+a[++i]]+a[++i]; cout<

OpenStudy (anonymous):

cout<<a[9]; //if u output 9

OpenStudy (anonymous):

ans is 9

OpenStudy (anonymous):

yes,

OpenStudy (anonymous):

i know ans is 9 how it came(evaluated)?

OpenStudy (anonymous):

This is a test of your understanding of order of operations. At std::cout you should see that i == 3. What is a[ 3 + a[3]] + a[3]?

OpenStudy (anonymous):

i evaluated like a[1+a[2]]+a[3]; tell me the logic of 3 at all places

OpenStudy (anonymous):

++i is evaluated first, so the function is: a[ 3 + a[3]] + a[3] not a[1+a[2]]+a[3] thus a[ 3 + a[3]] + a[3] == a[3 +3] + 3 == a[6] + 3 == 6 + 3 == 9

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!