// Attention: This code does not compile. Why? How do we fix it? #include #include #include /* * x is an array with N elements; there must be at least two elements * this function returns the second largest value among the elements of x */ int second_largest_of(int N, int x[]) { // precondition assert(N >= 2); // initialize largest and second_largest to the smallest possible int value int largest = std::numeric_limits::min(); int second_largest = std::numeric_limits::min(); for(int i = 0; i < N; i++) if(x[i] > largest) { second_largest = largest; largest = x[i]; } else if(x[i] > second_largest) second_largest = x[i]; return second_largest; } int main() { constexpr int fixed_array_size = 5; const int x[fixed_array_size] = {4, 0, 6, 5, 2}; std::cout << second_largest_of(fixed_array_size, x) << "\n"; }