my question is involving returning a reference. from playing around, i have only been able to get it to function (no pun intended xD) when its returning the adress of an element in an array. is it not possible to return a reference to a variable or am i doing something wrong? here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
using std::cout;
using std::endl;
int& changeNumber(int num);
int main()
{
int number = 50;
changeNumber(number) = 3;
cout << number << endl;
return 0;
}
int& changeNumber(int num)
{
return num;
}
just for reference(HAHHA ANOTHER PUN) here is the working code when using an array: