For this iterator which of the following is correct? If correct what does the expression produce?

Suppose we have the following definition:
```
vector vec;
// use push_back to put 10 values into vec here.
vector::iterator itr1, itr2,itr3;
itr1 = vec.begin();
itr2 = vec.begin() + 5;
itr3 = vec.end();
```

a) *iter1
b) itr2[3]
c) itr + 3
>>>there is no itr, Do you mean itr3?
d) itr – 3
e) itr3 – itr1 (if valid, what does this produce?)
>>You asked for what is produced for all of them in intro to question


All parts are correct.

Part a) is an expression that returns the first element in the vector. Part b) returns the middle + 3rd, i.e., the 8th element.
c) returns an iterator to the 8th element
d) returns an iterator to the (5-2)th element, that is, the 2nd element
e) Though not explicitly mentioned in the text, there is enough information there that the student should be able to deduce that this expression returns the number of elements between the front and the back of the vec.

Computer Science & Information Technology

You might also like to view...

What is the Server Core version of Windows Server 2008?

What will be an ideal response?

Computer Science & Information Technology

Rewrite bundle (page 451) so the script it creates takes an optional list of filenames as arguments. If one or more filenames are given on the command line, only those files should be re-created; otherwise, all files in the shell archive should be re-created. For example, suppose all files with the file- name extension .c are bundled into an archive named srcshell, and you want to unbundle just the files test1.c and test2.c. The following command will unbundle just these two files:

$ bash srcshell test1.c test2.c

Computer Science & Information Technology

Give some examples of applications where the use of mobile code is beneficial.

What will be an ideal response?

Computer Science & Information Technology

A(n) ____________________ is a tiny dot of light that, when taken together, form a grid on your screen to create images.

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

Computer Science & Information Technology