11.2k views
3 votes
Which assigns the array's last element with 99? int myvector[15];

A) myvector[14] = 99;
B) myvector[13] = 99;
C) myvector[15] = 99;
D) myvector[12] = 99;

User Mackendy
by
8.2k points

1 Answer

2 votes

Final answer:

To assign 99 to the last element of an array with 15 elements, use the index 14 since array indexing starts at 0. The correct statement is myvector[14] = 99.

Step-by-step explanation:

To assign the last element of an array myvector with the value of 99, you must access the element at index 14, as array indexing starts at 0 in C++. Therefore, the correct way to assign the value 99 to the last element of the array myvector[15] is to use the statement myvector[14] = 99;. So, the correct answer is A) myvector[14] = 99.

User Mbrc
by
8.3k points