21.2k views
3 votes
[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));

User Hacker
by
8.2k points

1 Answer

1 vote

Answer:

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

Step-by-step 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.

User Higginbotham
by
8.4k points