What is the difference between these two code snippet? Both of them returns a different results without raising any error.
int arr[] = { 15, 10, 5 };
sort(arr,arr+3);
for(auto it : arr){
std::cout<<it<<" "; // 5 10 15
}
int arr[] = { 15, 10, 5 };
sort(&arr[0],&arr[2]);
for(auto it : arr){
std::cout<<it<<" "; // 10 15 5
}
Can anyone please explain??!
I suddenly encounter this problem using this code, it is not sorting properly.
int arr[] = { 15, 10, 5 };
sort(&arr[0],&arr[2]);
for(auto it : arr){
std::cout<<it<<" ";
}
Then I searched for the right way to this, which is
int arr[] = { 15, 10, 5 };
sort(arr,arr+3);
cout<<endl;
for(auto it : arr){
std::cout<<it<<" ";
}