your question indicates that there might be quite a bit of confusion as to how one deals with pointers in C++. If my assumption is incorrect then just skip ahead(i will provide "my solution"/correction at the end of this post).
To answer your first question: you can't pass C-style arrays per value in C++, nor by reference for that matter. Your only "option" would be looping through the pointer until '\n' is reached & store the contents in a new array created in your function.
which would be something along the lines of
'{
int arrx[5] = {};
for(int i = 0; i < 5; i++)
{
arrx[i] = arr[i];
}
for (int j = 0; j < 5; j++) // print
{
std::cout << arrx[j];
}
return 0;
}`
A couple of other things about pointers:
int *sort(int arr[]){ -> arr[] passes a pointer to arr(same as *arr)
Pointer point to the first element in the memory pointed to & have no inherit size meaning
sizeof(arr) / sizeof(arr[0])
would not work inside your sort function(which could lead to problems if you dont know exactly how long the array you want to search is). a simple solution would be to pass the size of your array by value/reference to your function.
Another solution would be to loop through the array itself via something akin to
for(;arr != '\n'; arr++)
{
//your code here
You can get a lot more information about pointers than i could ever give you by visiting the various tutorial sites out there.
for example: https://www.tutorialspoint.com/cplusplus/cpp_pointers.htm
http://www.cplusplus.com/doc/tutorial/pointers/
But now back to your original question and hopefully an answer to it.
int *sort(int arr[]) {
for (int i = 0; i< 1; i++) {
should be corrected to for(int i=0; i< 5-1; i++)
the sorting function you are trying to implement is called bubblesort. for further information & how exactly bubblesort works please refer to https://de.wikipedia.org/wiki/Bubblesort
for (int j = 1; j< 5; j++) {
should be corrected to for(int i=0; i< 5-1-i; i++)
because the last elements are already in place.
if (arr[i]< arr[j]) {
should be corrected to if (arr[j]< arr[j+1])
because you want to compare(for example) the first element & the next element to get it in descending/ascending order. this gets done for every number pair in your array.
and finally:
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
should look something along the lines of:
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
please note that you can also reformat it to:
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp; // same output
as an example: if arr[j] = 5 and arr[j+1] = 6 then you store the value j+1(6) in temp, overwrite arr[j+1] with j(5) and lastly store 6 at j to get descending order(hope i got that right now, but you get the gist)
lastly; as others have correctly pointed out already, you can use std::swap
instead of using key/temp variables.