0
max_element function in c++
code 1: // #include<iostream> #include<algorithm> int main(){ int arr[7]{1,2,3,6,4,5,3}; int *m = std::max_element(arr, arr + 7); std::cout << *m; return 0; } // code 2: // #include<iostream> #include<algorithm> void rr(int arr){ int *m = std::max_element(arr, arr + 7); std::cout << *m; ; } int main(){ int arr[7]{1,2,3,6,4,5,3}; rr(arr) return 0; } // when i am compiling code 1 , it is ok. But when i am compiling 2nd one its saying error.Can anyone tell me what is the problem and how to solve it ? I want to take the max value from function
2 Réponses
+ 3
In the second code, you are trying to pass the array as a single integer, not as a pointer to integers. The parameter type should be int*.
There is also a semicolon missing after the function call to "rr()" in main.
0
Thanks for you reply ...
And sorry for late reply ....i was a little sick ......