## Exercise

1.What is the return value of f(p, p) if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value.

int find(int &x, int c)
{
c = c - 1;
if (c == 0) return 1;
x = x + 1;
return f(x, c) * x;
}
int main()
{
int p = 5;
printf("%d", find(p, p));
}

A. 3024
B. 6561
C. 55440
D. 161051

2.What is the output of this program?

using namespace std;
int &find()
{
static int p = 10;
return p;
}
int main()
{
find() = 30;
cout << find();
return 0;
}

A. Compiler Error: Function cannot be used as lvalue
B. 10
C. 30
D. 20

3.What is the output of this program?

using namespace std;
int &find()
{
int p = 10;
return p;
}
int main()
{
find() = 30;
cout << find();
return 0;
}

A. May cause runtime error
B. May cause compiler error
C. Always works fine
D. 0

4.Which of the following statement is correct about the program given below?

using namespace std;
int main()
{
int p = 10;
int& q = p;
q = 20;
cout << "p = " << p << endl ;
p = 30;
cout << "q = " << q << endl;
return 0;
}

A. p=20
q=30
B. p=20
q=20
C. p=10
q=30
D. p=30
q=30

5.Which of the following is true about the following program

using namespace std;
int main()
{
int p = 45;
int &q = p;
p++;
cout << p << " " << --q;
return 0;
}

A. The program will print the output 45 45.
B. The program will print the output 46 40.
C. The program will print the output 46 46.
D. It will result in a compile time error.

6.What will be the output of this program?

using namespace std;
int main()
{
int p = 45;
int q& = p;
p++;
cout << p << " " << --q;
return 0;
}

A. The program will print the output 45 45.
B. The program will print the output 46 40.
C. The program will print the output 46 46.
D. It will result in a compile time error.

7.What will be the output of this program?

using namespace std;
int main()
{
int p = 10, q = 20;
int *ptr = & p;
int &ref = q;
*ptr++;
ref++;
cout<< p << " " << q;
return 0;
}

A. The program will print the output 10 20.
B. The program will print the output 10 21.
C. The program will print the output 11 20.
D. The program will print the output 11 21.
E. It will result in a compile time error.

8. What will be the output of the following program?

using namespace std;
enum find
{
a, b, c
};
int main()
{
int x = a, y = b, z = c;
int &p = x, &q = y, &r = z;
p = ++x;
q = ++y;
r = ++c;
cout<< p << q << r;
return 0;
}

A. The program will print the output 1 2 3.
B. The program will print the output 2 3 4.
C. The program will print the output 0 1 2.
D. It will result in a compile time error.

9. What will be the output of the following program?

using namespace std;
class find
{
int x, y;
public:
void SetValue(int &xx, int &yy)
{
x = xx++;
y = yy;
cout<< xx << " " << yy;
}
};
int main()
{
int x = 10;
int &y = x;
find obj;
obj.SetValue(x , y);
return 0;
}

A. The program will print the output 10 10.
B. The program will print the output 10 11.
C. The program will print the output 11 10.
D. The program will print the output 11 11.
E. It will result in a compile time error.

10. What will be the output of the following program?

using namespace std;
class course
{
int x, y;
public:
course(int xx = 0, int yy = 0)
{
x = xx;
y = yy;
}
void Display()
{
cout<< x << " " << y;
}
course operator +(course z)
{
course temp;
temp.x = x + z.x;
temp.y = y + z.y;
return temp;
}
};
int main()
{
course obj(90, 80);
course obj2(10, 20);
course objSum;
course &ref = objSum;
ref = obj + obj2;
ref.Display();
return 0;
}

A. It will result in a runtime error.
B. It will result in a compile time error.
C. The program will print the output 9 4.
D. The program will print the output 100 100.