Consider the following array definition: int values[5] = { 4, 7, 6, 8, 2 }; What does each of the following statement display? cout << values[4] << endl; __________ cout << (values[2] + values[3]) << endl; __________ cout << ++values[1] << endl; __________

Respuesta :

Answer:

2                                                                                                                              

14                                                                                                                            

8  

respectively.

cout << values[4] << endl; ________2

cout << (values[2] + values[3]) << endl; _______14  

cout << ++values[1] << endl; __________8  

Explanation:

The code is written in C++

  • int values[5] = { 4, 7, 6, 8, 2 };

The code above is an array with a length of 5.

In C++ indexing starts from "0". In this array we have 5 elements  stores in index 0,1,2,3 and 4.

0 = 4

1 = 7

2 = 6

3 = 8

4 = 2

  • cout << values[4] << endl; ________2

prints out the value stored in index [4] which is 2.

  • cout << (values[2] + values[3]) << endl; _______14  

adds(+) the values stored in index [2] and [3].  i.e. 6+8 = 14. it then prints out the summation.

  • cout << ++values[1] << endl; __________8  

(++value increases the value by 1.)

prints out the increment of the value stored in index[1]. i.e. 1+7=8

ACCESS MORE
EDU ACCESS