0

Please explain this 🙏

#include <iostream> using namespace std; int main() { int a[3]={2,7,3}; for (int i=0;i<3;i++){ a[i]-=i; } cout <<a[1]; return 0; }

19th Jun 2016, 3:44 AM
Unknown
Unknown - avatar
4 Answers
+ 1
Can you please explain a[1]=a[1]-1
19th Jun 2016, 4:11 AM
Unknown
Unknown - avatar
+ 1
a[1] equals to 7. a[1]=a[1]-1 is the same as a[1]=7-1. 7-1 equals to 6. That means, that a[1] is getting the value 6.
21st Jun 2016, 11:18 PM
MaxCode
0
answer is 6 EXPLANATION: First we made an array and gave values to it. Now using for loop we change the values stored in the array. As a[i]-=i is equivalent to a[i] = a[i] - i. So when i =1, its a[1]=a[1]-1 ( a[1]=7-1) which comes out to be 6. hope this helped!!
19th Jun 2016, 4:07 AM
Tanish Agarwal
Tanish Agarwal - avatar
0
its normal algebra. like if x =7 and we write x = x - 1. similarly a[1] is 7 and we are changing its value by that algebraic expression. did this help?
19th Jun 2016, 4:18 AM
Tanish Agarwal
Tanish Agarwal - avatar