I have used a vector as: vector<int> v(2)
Now I have pushed digit 1 to the vector.
Now when I will try to print the elements of v then the output will be as 0 0 1 Why the leading 2 zeroes are coming although I have not pushed them to the vector?
I have used a vector as: vector<int> v(2)
Now I have pushed digit 1 to the vector.
Now when I will try to print the elements of v then the output will be as 0 0 1 Why the leading 2 zeroes are coming although I have not pushed them to the vector?
The two zeroes are there, because you created a vector with two zeroes. You could overwrite them, but push_back
adds another value instead of overwriting existing elements.