1
How can we prevent popping from a vector when there is no elements in a vector?
2
What occurs behind the scene when we push-back a value to a vector?
3
Which statement is required for the compiler to recognize your code when you are using a vector
Answer 1: Before popping an element we can check if the vector size is 0 i.e. if vector is not empty then only perform the pop operation.
Answer 2: When we push-back value to the vector, resizing of vector takes place. Vector size increase when we push-back the element in the vector and this element is inserted at the end of the vector.
Answer 3: #include<vector> tells the compiler not use your own code only, but to also compile a header file called vector. The compiler only knows the C++ language, not its standard library. So we cannot use vector without writing this line at the start of the program.
Get Answers For Free
Most questions answered within 1 hours.