159
C++ Vector resize()
It modifies the size of the vector to the specified value
Size changed to 4 and new value is
Syntax
Consider a vector v. Syntax would be:
Parameter
n : It is the new vector size.
val : If n is greater than the current vector size, then value(val) is inserted in the added space.
Return value
It does not return any value.
Example 1
Let’s see a simple example when n is less than the current vector size.
Output:
Initial elements are: 1 2 3 4 5 6 7 8 9 10 After resizing its size to 5, elementsare: 1 2 3 4 5
Example 2
Let’s see a simple example n is greater than the current vector size.
Output:
Elements of v1 are :java C C++ java C C++ .Net .Net
Next TopicC++ Vector