C++ Programming Multiple Choice Questions - References
This section focuses on the "References" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Reference is like a?
View Answer
2. A References is :
View Answer
3. A variable can be declared as reference by putting _______ in the declaration.
View Answer
4. If a function receives a reference to a variable, can it modify the value of the variable?
View Answer
5. Through references we can avoid?
View Answer
6. References can be NULL?
View Answer
7. How many objects reference can refer during its lifetime?
View Answer
8. Dereference operator is also called as
View Answer
9. Which operator is used to de-references to an object?
View Answer
10. Which of the following is an advantage of reference?
View Answer
11. 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.
#include <iostream>
using namespace std;
int LFC(int &x, int c)
{
c = c - 1;
if (c == 0) return 1;
x = x + 1;
return LFC(x, c) * x;
}
int main()
{
int p = 5;
printf("%d", LFC(p, p));
}
View Answer
12. What is the output of this program?
#include <iostream>
using namespace std;
int &LFC()
{
static int p = 10;
return p;
}
int main()
{
LFC() = 30;
cout << LFC();
return 0;
}
View Answer
13. What is the output of this program?
#include <iostream>
using namespace std;
int &LFC()
{
int p = 10;
return p;
}
int main()
{
LFC() = 30;
cout << LFC();
return 0;
}
View Answer
14. Which of the following statement is correct about the program given below?
#include <iostream>
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;
}
View Answer
15. Which of the following is true about the following program
#include <iostream>
using namespace std;
int main()
{
int p = 45;
int &q = p;
p++;
cout << p << " " << --q;
return 0;
}
View Answer
16. What will be the output of this program?
#include <iostream>
using namespace std;
int main()
{
int p = 45;
int q& = p;
p++;
cout << p << " " << --q;
return 0;
}
View Answer
17. What will be the output of this program?
#include <iostream>
using namespace std;
int main()
{
int p = 10, q = 20;
int *ptr = & p;
int &ref = q;
*ptr++;
ref++;
cout<< p << " " << q;
return 0;
}
View Answer
18. What will be the output of the following program?
#include <iostream>
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;
}
View Answer
19. What will be the output of the following program?
#include <iostream>
using namespace std;
class LFC
{
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;
LFC obj;
obj.SetValue(x , y);
return 0;
}
View Answer
20. What will be the output of the following program?
#include <iostream>
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;
}
View Answer
21. Which value can we not assign to reference?
View Answer
22. The terms lvalue and rvalue is referred to the things that appears on
View Answer
23. Which of the following statements is correct?
i) Once a reference variable has been defined to refer to a particular variable it can refer to any other variable.
ii) A reference is not a constant pointer.
View Answer
24. Which of the following statements is correct? i) Change a reference changes the referent. ii) We can create an array of references.
View Answer
25. Which of the following statement is correct?
View Answer
Also check :
Discussion