References Questions
Practice References MCQs with answers and explanations. Page 3 of 3.
Category
C++ Programming
Topic
References
Page
3 / 3
Mode
Practice
Questions
Open any question to view the answer and explanation.
C++ lvalue references cannot bind to rvalues: detect the error with post-increment operands.
#include <iostream.h>
int main() {
int m = 2, n = 6;
int &x = m++;
int &y = n++;
m = x++;
x = m++;
n = y++;
y = n++;
cout << m << " " << n;
return 0;
}
Open
View answer
C++ constructor parameters assigned via this-> and no Display call: what prints?
#include <iostream.h>
class Tab {
int x, y;
public:
Tab(int x, int y) { this->x = x; this->y = y; }
void Display() { cout << x << " " << y; }
};
int main() {
int x = 50; int &y = x;
Tab b(y, x); // no call to Display()
return 0;
}
Open
View answer
In C++ programming, consider the following two statements about references:
A reference is not a constant pointer, but rather an alias for an existing object.
A reference is automatically dereferenced when it is used in an expression, so you access the referred value without using the * operator.
Which one of the following options correctly describes these two statements?
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.