This is a nice trick question,actually the catch is when you are passing to foo you are sending address of p and in the main function the definition of p remains the same,its a single pointer, when you are changing the single pointer to p in foo itself its value gets changed.So,it will print 2 and 2.If you have doubts better debug this code.