Can you please explain me why the heck do I get this output? I expected to see:
2 4 2
3 9 9
Instead I have:
2 4 2
9 9 3
#include <iostream>
using namespace std;
int sq1(int);
int sq2(int&);
int main() {
int x = 2, y = 3;
cout<<x<<" "<<sq1(x)<<" "<<x;
cout<<endl;
cout<<y<<" "<<sq2(y)<<" "<<y;
return 0;
}
int sq1(int n) {
n *= n;
return n;
}
int sq2(int &n) {
n *= n;
return n;
}