functions pass by reference and pass by value

The correct answer is actually 2 0 0.
I understand why 2 is the answer but i dont understand the 0 0. Can someone please explain it? Im ready to pull my hair out.

#include <iostream>
using namespace std;

void doSomething(int&);

int main()
{
int x = 2;

cout << x << endl;
doSomething(x);
cout << x << endl;
return 0;
}

void doSomething(int& num)
{
num = 0;
cout << num << endl;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include <iostream>
using namespace std;

void doSomething(int&);

int main()
{
int x = 2;

cout << x << endl;
doSomething(x);
cout << x << endl;
return 0;
}

void doSomething(int& num)
{
num = 0;
cout << num << endl;
}
duplicate post. use other one.
Topic archived. No new replies allowed.