Which of the following could you use to declare the iterator p? Why?

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 << “ “;
```

```
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...

The ________________ provides a complete set of prototype controls to enable a comprehensive security response.

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

Computer Science & Information Technology

Which of the following must be true when making a method call?

a) The number of arguments in the method call must match the number of parameters in the method header. b) The argument types must be compatible with their corresponding parameter types. c) Both a and b. d) None of the above.

Computer Science & Information Technology