int myArr[5]; for(int x=0; x<5; x++) { myArr[x] = 42; } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

int myArr[5]; for(int x=0; x<5; x++) { myArr[x] = 42; }

I can't understand can somebody explain me plss

10th Dec 2017, 5:33 PM
utkarsh
2 Answers
+ 3
x variable is going to be used within for loop, as an index of the array myArr[]. That array's size has been defined at the time of declaration. 5. So we are going to loop for x until it reaches 4 (x<5). because array's index are 0 based. so last element (5th) will be at the index 4. In every loop, myArr[x] is 42. Since x will be from 0 to 4, myArr's every element will be 42.
10th Dec 2017, 5:38 PM
Sarthak Joshi
Sarthak Joshi - avatar
0
thanks
10th Dec 2017, 5:40 PM
utkarsh