0

please explain me why this output is 2 3 20

#include<iostream> using namespace std; int main() { int i[5]={2,5,15,20,30}; int a,b,c,d,e; e=3; c=1; d=0; a=++i[d]; b=i[d]--; c=i[a--]; cout<<a<<" "<<b<<" "<<c; }

27th Dec 2018, 6:41 PM
Ahmad Sheikh
Ahmad Sheikh - avatar
2 Réponses
+ 3
Please edit your question and use adequate tags. https://www.sololearn.com/discuss/1316935/?ref=app
27th Dec 2018, 6:50 PM
Anna
Anna - avatar
+ 2
a=++i[d] increments i[d] and assigns it to a. i[d] becomes 3 and its assigned to a. b=i[d]-- assigns i[d] to b so b is now 3 and then decreases i[d] so i[d] becomes 2 again. c=i[a--] assigns i[a] to c. remember a was 3 so i[3] is 20. so c is 20. but there is a-- inside bracket so a decreases and becomes 2. hence a b c is 2 3 20
27th Dec 2018, 7:49 PM
Asirap