Selection sort problem

in the code given here we have used a function which has void as its return type. hence it should not return anything.
but in the main function when we call the function and after that when we cout all the elements of the array then on the output screen it shows sorted modified array.
since nothing is returned to array in main so ideally it should print the unsorted array which we inputted in the beginning.

but when we talk about an int variable for eg

#include
using namespace std;
void fn(int a)
{
a=420;
}
int main()
{
int a;
a = 24;
fn(a);
cout<<a;
return 0;
}

here we see 24 as the output but not 420.
similarly in that selection sort code we should get the unsorted array which we inputted in the beginning as the output but we get sorted array.

does an integer array and an integer variable work differently in a function???

@pushkar24sharma yes they work diff in function passing
integer array is passed by ref automatically so it gets changed , but normal integer is passed by val so it dont.

1 Like

ok thank u @vatsal38 sir.