Quote (bomben @ Oct 14 2013 02:46pm)
How does it work? For me it looks like magic '-', example;
I got a function
Code
void max_min(int V[], int n, int &min, int &max)
{
//Add code
}
and when I call it like this
Code
int n = 12;
int V;
int min = 0;
int max = 0;
max_min(V,n,min,max);
Why can I rename min/max to what ever I want and it still compiles correctly? What information am I missing?
Thanks
& - pretty much means that you're using a pointer to a variable, so instead of having the program go "here's the value for x, work on it", it says "here's the location where x is, do whatever you want to it"
In every function the variable names are locally declared, so if you do
Code
void swap(int& x, int& y){
int temp = x;
x = y;
y = temp;
}
you can plug any integer values and variables from any other function in there.