Suppose we are given an STL vector container named vec that holds values of type double. What do each of vec[vec.size()-1], vec.back(), *(vec.end()-1), *(vec.begin()+vec.size()-1)and *vec.rbegin() mean?

What will be an ideal response?


They all evaluate to the last element of the container. The first expression gives the vector the largest legal index, producing the last element. The second expression returns the back element. The third starts with an iterator one past the end, and move one towards the front. Dereferencing give the last element. The next expression begins with an iterator to the first element, adds one less than the size, giving an iterator to the last element. Dereferencing gives the last element. Finally, the rbegin() member returns an iterator to the last element (the beginning element in reverse traversal of the vector elements). Dereferencing gives the last element.

Computer Science & Information Technology

You might also like to view...

The output stream connected to the computer screen is:

(a) System.exit (b) System.quit (c) System.in (d) System.out

Computer Science & Information Technology

A bar chart

A) compares values across categories using horizontal bars. B) separates one or more pie slices from the rest of the pie chart. C) shows each data point in proportion to the whole data series as a slice in a circular pie. D) uses a line to connect data points in order to show trends over a period of time.

Computer Science & Information Technology

It's easy to nest lists in HTML: you simply insert valid code for a list within the content of anlielement..

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

Computer Science & Information Technology

Which of the following statements about the else-if construct is false?

A. The else-if is a multiway selection. B. The else-if is a C construct. C. The else-if is used when the expression is not an integral type. D. The last test in an else-if series concludes with only an else, which is then the default action. E. The else-if should be used only then the same basic expression is being evaluated in the multiway selection.

Computer Science & Information Technology