0
can someone explain this ? a[0]=3?
int main() { int a[3]={1,2,3,}; for(int i=0;i<3;i++){ a[0]+=a[i]; } cout<<a[0]; //Output 6 }
7 Respostas
+ 3
I would recommend taking a look at the supposed output...
(imho 4+3 is not 6, but what do I know)
+ 2
Array a[3] is assigned 3 numbers: "1, 2, 3". => а=[1, 2, 3];
Further, using the cycle a[0] is assigned the sum of these numbers. => а=[7, 2, 3];
1. а[0]=1+1;
2. а[0]=2+2;
3. а[0]=4+3; // 7
+ 2
Antonio Mariani stuff like that happens to me often enough too
+ 1
Grigoriadis Georgios, Antonio Mariani
Explain to me how you managed to get the answer 6? 😂
👇
So
0: a[0]+a[0] //1+1;a[0]=2
1: a[0]+a[1] //2+2;a[0]=4
2: a[0]+a[2] //4+3;a[0]=6 ??? 😂
output: a[0]=6 ->output=6
0
Thanks for answers.