guys please help

Given the following program, show the values of the array in the figure:

int main() {
int values[5] = {3}; // <--------------- Array created
for(int i = 1; i < 5; i++) { // <----- Loop iterating...
values[i] = i;
} // <----------------------------------- Loop completed
values[0] = values[1] + values[4]; // <–- Last line before return
return 0;
}
After “Array created”
0=?
1=?
2=?
3=?
4=?
After the first iteration
of for loop
0=?
1=?
2=?
3=?
4=?
After “Loop completed”
0=?
1=?
2=?
3=?
4=?
After “Last line before
return”
0=?
1=?
2=?
3=?
4=?
Last edited on
What do you want?
i want to know what value is assigned to the array from 0-4 in certain conditions
the values are assigned in your program but you didn't order the program to output the values (use cout <<) here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

int main() {

int values[5] = {3};

for(int i = 1; i < 5; i++) {
values[i] = i;
}

values[0] = values[1] + values[4];

for (int a=0;a<5;a++)
{
    cout << values[a] << endl;
}
return 0;
}


sorry for my bad English.
Topic archived. No new replies allowed.