Sorry if the question is very basic.
PROGRAM 1:
#include <iostream>
using namespace std;
int max(int &a)
{
a +=100;
return a;
}
int main ( int argc, char ** argv)
{
int x=20;
int y;
y = max(x);
cout <<"x , y value is "<<x<<"and"<<y<<endl;
}
OUTPUT:
x, y value is 120and120
PROGRAM 2:
#include <iostream>
using namespace std;
int & max(int &a)
{
a +=100;
return a;
}
int main ( int argc, char ** argv)
{
int x=20;
int y;
y = max(x);
cout <<"x , y value is "<<x<<"and"<<y<<endl;
}
OUTPUT:
x, y value is 120and120
The only difference between PROGRAM1 and PROGRAM2 is that the second program returns by reference. What is exactly the difference?