Escolar Documentos
Profissional Documentos
Cultura Documentos
myList[0] 5.6
myList[1] 4.5
myList[2] 3.3
myList[3] 13.2
myList[4] 4.0
Array element at
myList[5] 34.33 Element value
index 5
myList[6] 34.0
myList[7] 45.45
myList[8] 99.993
myList[9] 111.23
C++ requires that the array size used to declare an array must be a
constant expression. For example, the following code is illegal:
int size = 4;
double myList[size]; // Wrong
But it would be OK, if size is a constant as follow:
const int size = 4;
double myList[size]; // Correct
arrayName[index];
double myList[4];
myList[0] = 1.9;
myList[1] = 2.9;
myList[2] = 3.4;
myList[3] = 3.5;
int main()
{ After the array is created
int values[5]={0,1,2,3,4}; 0 0
for (int i = 1; i < 5; i++) 1 1
{ 2 2
} 4 4
int main()
{ After the array is created
int values[5]={0,1,2,3,4}; 0 0
for (int i = 1; i < 5; i++) 1 1
{ 2 2
} 4 4
int main()
{ After the array is created
} 4 4
int main()
{ After the first iteration
} 4 4
int main()
{
int values[5] ={0,1,2,3,4}; After the first iteration
{ 1 1
2
2
values[i] = values[i] + 3 3
values[i-1]; 4 4
}
values[0] = values[1] +
values[4];
}
{ 0 0
values[i] = values[i] + 1 1
values[i-1]; 2 2
3 3
} 4
4
values[0] = values[1] +
values[4];
}
int main()
{ After the second iteration
} 4 4
int main()
{ After the second iteration
} 4 4
int main()
{ After the second iteration
} 4 4
int main()
{ After the third iteration
} 4 4
int main()
{ After the third iteration
} 4 4
int main()
{ After the third iteration
} 4 4
int main()
{ After the fourth iteration
} 4 10
int main()
{
int values[5] ={0,1,2,3,4};
for (int i = 1; i < 5; i++)
{ After the fourth iteration
values[i] = values[i] + values[i-1];
} 0 0
values[0] = values[1] + values[4]; 1 1
} 2 3
3 6
4 10
int main()
{
int values[5] ={0,1,2,3,4};
for (int i = 1; i < 5; i++) After the fourth iteration
{
values[i] = values[i] + values[i-1]; 0 0
1 1
} 2 3
} 4 10
int main()
{
int values[5] ={0,1,2,3,4};
for (int i = 1; i < 5; i++) 0 11
{ 1 1
} 3 6
double total = 0;
for (int i = 0; i < ARRAY_SIZE; i++)
{
total += myList[i];
}