0

Array!

I still don’t get some part of array. So, the number in the array will be changed simultaneously if the number in for function was changed? I mean like int arr [] = {this numbers} are combined with for (x=0;x<this number;x++)? But, how do we recognize them? Sorry for my explanation but it’ll be thankful if someone can answer this!

18th Nov 2017, 5:43 AM
Ryuya Kimura
Ryuya Kimura - avatar
3 Answers
+ 5
for loop is one of common ways to iterate array, but if you don't specifically put instructions that alters the array's elements nothing will happen with them, for example: // Here we have an array with 5 elements int ar[] = {1,2,3,4,5}; for(int i = 0; i < 5; i++) { // this will only print elements' value cout << ar[i]; } but if we go like this: for(int i = 0; i < 5; i++) { // this will square elements' value ar[i] *= ar[i]; } Hth, cmiiw
18th Nov 2017, 6:00 AM
Ipang
0
I appreciate you guys!
26th Nov 2017, 1:47 AM
Ryuya Kimura
Ryuya Kimura - avatar