answersLogoWhite

0

When the size of vetor is fixed in c plus plus?

Updated: 8/19/2019
User Avatar

Wiki User

10y ago

Best Answer

The size of a vector cannot be fixed because a vector is a wrapper for a dynamic array where resizing occurs automatically (by virtue of the vector class). So, even if you reserved enough memory for n elements in advance, the vector will resize automatically as soon as you push more than n elements. A normal dynamic array does not resize automatically (you have to manually resize the array in order to accommodate more elements than you've allowed), and is therefore more suitable for a fixed size dynamic array. However, if you embed a vector in your own class wrapper (such as fixed_vector), you can reserve n elements in the vector via the constructor, and subsequently control how many elements are pushed onto the vector. Once n elements are pushed, any subsequent elements can be ignored, perhaps raising an exception for added safety.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When the size of vetor is fixed in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the size of a blank class in C plus plus?

Try 'sizeof', it will return the size in bytes.


Why you use zero instead of NULL in c plus plus?

In C++ NULL is defined as 0. It's a design failure, will be fixed with a new 'nullptr' keyword.


What is the maximum size of else-if ladder in c plus plus?

There is no preset limit on the size of an else-if ladder in C++. It depends on compiler design and available memory.


How do you calculate the size of a class in memory in C plus plus?

Use sizeof( ).


What are arreys in c?

arrays in C are the data types which have collection of same type of data together store a fixed-size s of elements .


What is the operator that cannot be overloaded in c plus plus and java?

conditional operator , size of operator , membership operator and scope resulation operator can not be overload in c++


What is syntax in c plus plus for declaring a variable?

type variable {[optional array size]} {= optional initializer};


Is the array size is fixed after it is created?

Generally, a array is fixed in size. With some libraries, however, they are extensible, either by reallocation/copying strategies (C/C++/STL), or by linking/referencing strategies (JAVA).


Where to buy inexpensive plus size bathing suits in the U.K.?

It is always difficult to find that right fitting bathing suit no matter what size or shape you are. If you are looking for plus size bathing suits in the UK, try this website. http://www.ukswimstore.com/c-5-plus-size-swimwear.aspx


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


How is a bitwise copy created in c plus plus?

You could just use memcpy(3), using sizeof() to get the object size.