CS 111 (Chapter 10) – Flashcards

Unlock all answers in this set

Unlock answers
question
Which statement correctly defines a vector object for holding integers?
answer
vectorv;
question
Which statement correctly uses C++ 11 to initialize a vector of ints named n with the values 10 and 20?
answer
vectorn{ 10,20 };
question
What does the following statement do? vectorv(10);
answer
it creates a vector object with a starting size of 10
question
What will the following C++ 11 code display? vector numbers { 3,5 }; for (int val: numbers) cout << val << endl;
answer
3 5
question
What does the following statement do? vector v(10, 2);
answer
It creates a vector object with a starting size of 10 and all elements are initialized with the value 2
question
This vector function is used to insert an item into a vector
answer
push_back
question
This vector function returns the number of elements in a vector
answer
size
question
This vector function removes an item from a vector
answer
pop_back
question
This vector function returns true if the vector has no elements
answer
empty
question
True/False: A vector object automatically expands in size to accommodate the items stored in it
answer
True
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New