In: Computer Science
How do i change the vector v to size 20 in C++.
Also given the following, which line of code stores 40 into the 4th column of the 6th row of array dataVals?
const int rows = 7;
const int cols = 5;
int dataVals[rows][cols];
Select one:
a. dataVals[5, 3] = 40;
b. dataVals[5 * 3] = 40;
c. dataVals[3][5] = 40;
d. dataVals[5][3] = 40;
1. To increase the Size of vector in C++ , twn method can use
.
[1] resize();
The resize() method (and passing argument to
constructor is equivalent to that) will insert or delete
appropriate number of elements to the vector to make it given size
(it has optional second argument to specify their value).
It will affect the size(), iteration will go
over all those elements, push_back will insert after them and you
can directly access them using the operator[].
[2] reverse();
method only allocates memory, but leaves it
uninitialized. It only affects capacity(), but size() will be
unchanged. There is no value for the objects, because nothing is
added to the vector.
If you then insert the elements, no reallocation will
happen, because it was done in advance, but that's the only
effect.
2. Array Will start From [0][0] and end with [n-1][m-1] for
dataVals[n][m]
So [D] dataVals[5][3] = 40 Correct Answer