void func(int x) {
x = 2;
}
int main()
{
int x = 3;
func(x);
cout << "x = " << x << endl;
return 0;
}
I expect the out put to be 2. Why isn't this happening? A simple explanation since I only just started learning c++ please. Could you then explain why the following yields 5:
void func(int x)
{
x = 2;
}
void function(int *x)
{
*x = 5;
}
int main()
{
int x = 3;
func(x);
function(&x);
cout << "x = "<< x << endl;
return 0;
}