The function doSomething accepts the argument as reference.So whatever changes are made in the function to the argument the changes will be reflected onto the original arguments.
First the value of x is 2.Hence 2 is printed first.
Then function doSomething is called that changes the value of x from 2 to 0 and then prints it.Hence 0 is printed in the newline.
Then in the main function x is printed again the function changed it's value so 0 is printed.