[C++11]: Given a built-in array of ints named values, which of the following statements would sort the array?
A.sort(values.begin(), values.end());
B.sort(values.array_begin(), values.array_end());
C.sort(begin(values), end(values));
D.sort(array_begin(values), array_end(values));

Answer :

alimir

Answer:

C. sort(begin(values), end(values));

Explanation:

In c++, arrays are passed as arguments in the std function sort. Therefore inside to sort function, the begin function and end function would take the array as argument. The correct syntax of the sort function is:

sort( startaddressofarray, endaddressofarray)

Options A and  B are treating the array as on object or class with its own functions. This is untrue in c++. In Option D, the name of the function is incorrect begin and end are incorrect.

Other Questions