I was studying about references and i was trying a program to pass an rvalue to a function as reference argument, like this.
#include<iostream>
using namespace std;
int fun(int &x)
{
return x;
}
int main()
{
cout << fun(10);
return 0;
}
but this didn't work, when i tried to pass an lvalue, It worked.
#include<iostream>
using namespace std;
int fun(int &x)
{
return x;
}
int main()
{
int x=10;
cout << fun(x);
return 0;
}
can someone explain me why this happens?