Are these two Things the same???
- vector v(100);
and - vector v;
v.reserve(100);
If these Two are not same then please share the diffrences
Are these two Things the same???
If these Two are not same then please share the diffrences
Hey, when you declare a vector as
vector<int> v(100);
vector constructor will be called and initialize the vector v with default size 100.
but when you write this
vector<int> v1;
v1.reserve(100);
vector v1 will have a reserved space of 100 but its size will be 0 at that time, its size will depend upon how many elements are added to it.
you can test this using this code snippet:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v(100);
cout<<v.size()<<endl;
vector<int> v1;
v1.reserve(100);
cout<<v1.size()<<endl;
}
Thank you for the help