Suppose you want to run code that involves the loop

//Assume vector v and iterator p has been defined and
//given appropriate values
for (p = v.begin(); p != v.end(); p++)
cout << *p << " ";
Which of the following could you use to declare the iterator p? Why?
std::vector::iterator p;
std::vector::const_iterator p;


You could use either, but you probably should use const_iterator. In the loop, the iterator p is used to fetch from the container. There is no code that would change the container’s contents.

Computer Science & Information Technology

You might also like to view...

Describe the specific steps you will follow during a preliminary investigation, including any fact-finding techniques you will use. Be sure to include the tools mentioned in this chapter.

What will be an ideal response?

Computer Science & Information Technology

Which of the following is NOT a method of advancing to the next slide during a presentation?

A) Using a mouse B) Using voice control C) Using gestures D) Using the keyboard

Computer Science & Information Technology

To create a complement mask, we set the bits to be complemented to 1 and the rest of the bits to 0.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Two devices on a network negotiate their communication protocols through a process called ___________.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology