(b) (12 marks) The C++ language supports both pointer and reference variables. Suppose y is
an integer variable. Then the following declaration
int &x = y;
will create a reference variable x and initialize x with the reference of y. An alias is thus
created between x and y. Any assignment to or evaluation of x is actually performed on y.
Give the output of the four print statements in the following C++ program. Explain your
answers with the help of memory diagrams to give step by step changes to the contents of
all variables (pointer, reference and integer).
int main() {
int a = new int;
int b = new int;
int *p;
*a = 500;
*b = 300;
p = a;
*a = 0;
printf("%d %d %d\n", *p, *a, *b);
b = p;
p = b;
*b = 400;
*p = *a;
printf("%d %d %d\n\n", *p, *a, *b);
int &r = *a;
*a = 1000;
*b = 200;
*a = 300;
b = p;
printf("%d %d %d\n", r, *a, *b);
r = *b;
*b = 400;
printf("%d %d %d\n", r, *a, *b);
return 0;}