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!
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
0
I appreciate you guys!