0
i dont understand this myarr[x]? what it means
int myArr[5]; for(int x=0; x<5; x++) { myArr[x] = 22; cout << x << ": " << myArr[x] << endl;
2 ответов
+ 16
myArr is an array capable of holding 5 integers.
The array values start as myArr[0],myArr[1]....myArr[4] so overall 5 integres can be stored.
So by using for loop you are storing value of 22 in all these places and then printing it.
The output will be in form:-
0:22
1:22
2:22
3:22
4:22
+ 3
it will be like what @Sld stated.
To break it down in simpler terms :
'myArr' can store up to 5 elements.
I am making a loop by creating a new variable 'x' and making it 0. For each time 'x' is below 5, I will make the element number 'x' in myArr 22
[Basically the first loop, x will be 0, so in `myArr[0] = 22;` , would be as simple as making the element no.0 in myArr storing a value of 22.]
[ On the second loop, x will be 1, so , `myArr[1] = 22;` and you should get what I mean]
Finally, output the element inside the array, then add 'x' by one.