144k views
3 votes
Assume you define a vector in the following way:

vector vec;

Assign the value 10 to the first element of this vector. What is the statement you would use?

User Kalitsov
by
4.9k points

1 Answer

1 vote

Answer:

vec[0].push_back(10)

Step-by-step explanation:

Given

Declaration: vector <int> vec

Required

Assign 10 to the first element

This can be done using the push_back keyword.

The syntax is: vectorname[position].push_back(value);

In this case:

vectorname = vec

position = 0 i.e. first element

value = 10

So, we have:

vec[0].push_back(10)

User Daniel Jomphe
by
4.8k points