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

To reset the format state of the output stream:

a. Call the reset member function. b. Call the flags member function with the ios_base::fmtflags constant as the argument. c. Save a copy of the fmtflags value returned by calling member function flags before making any format changes, and then call flags again with that fmtflags value as the argument. d. You must manually apply each individual format change member function or stream manipulator to restore the default format state.

Computer Science & Information Technology

What is the output of the following code fragment?

float *p1; p1 = new float(3); cout << *p1; a. 3.0 b. unknown, the address p1 points to is not initialized c. unknown, the code is illegal, p1 points to a dynamic array d. 0.0

Computer Science & Information Technology

An HIDPS can detect local events on host systems and detect attacks that may elude a network-based IDPS.

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

Computer Science & Information Technology

If the array: 6, 21, 35, 3, 6, 2, 13 is added to a stack, in the order given, which of the following is the top of the stack?

a) 2 b) 6 c) 3 d) 13 e) 35

Computer Science & Information Technology