Our experts have gathered these Operator Overloading MCQs through research, and we hope that you will be able to see how much knowledge base you have for the subject of Operator Overloading by answering these 20 multiple-choice questions.
Get started now by scrolling down!
Output of following program?
#include <iostream>
using namespace std;
class Test2
{
int y;
};
class Test
{
int x;
Test2 t2;
publi
operator Test2 () { return t2; }
operator int () { return x; }
};
void fun ( int x) { cout << "fun(int) called"; }
void fun ( Test2 t ) { cout << "fun(Test 2) called"; }
int main()
{
Test t;
fun(t);
return 0;
}
A.
fun(Test 2) called
B.
fun(int) called
C.
Compiler Error: Ambiguous call to fun()
A. None of these
B. Protected
C. Private
D. Public
A. Function overloading,
B. Virtual tables
C. Operator overloading
A. True
B. False
A. True
B. False
A. .* (Pointer-to-member Operator )
B. :: (Scope Resolution Operator)
C. . (Member Access or Dot operator)
D. ?: (Ternary or Conditional Operator )
E. All of these
A. False
B. True
A. False
B. True
A. Comparison Operator
B. Postfix ++
C. Prefix++
D. Insertion Operator <<
A. True
B. False
A. A group function with the same name
B. All
C. All have the same number and type of arguments
D. Functions with same name and same number and type of arguments
A. True
B. False
A. A class is declared
B. A object is declared
C. A class is used
D. An object is used
A. By making an empty private new operator.
B. By making an empty private new and new[] operators
C. By overloading new operator and new[] operators
D. By overloading new operator
A. C++ doesn't allow both operators to be overlaoded in a class
B. A postfix ++ has a dummy parameter
C. A prefix ++ has a dummy parameter
D. By making prefix ++ as a global function and postfix as a member function.
Which of the following operators are overloaded by default by the compiler?
1) Comparison Operator ( == )
2) Assignment Operator ( = )
A.
Only 1
B.
None of the two
C.
Both 1 and 2
D.
Only 2
A. All of these
B. New
C. Conversion Operator
D. Delete
Predict the output?
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
using namespace std;
class Test {
int x;
publi
void* operator new(size_t size);
void operator delete(void*);
Test(int i) {
x = i;
cout << "Constructor called \n";
}
~Test() { cout << "Destructor called \n"; }
};
void* Test::operator new(size_t size)
{
void *storage = malloc(size);
cout << "new called \n";
return storage;
}
void Test::operator delete(void *p )
{
cout<<"delete called \n";
free(p);
}
int main()
{
Test *m = new Test(5);
delete m;
return 0;
}
A.
Constructor called
new called
delete called
Destructor called
B.
Constructor called
new called
Destructor called
delete called
C.
new called
Constructor called
Destructor called
delete called
D.
new called
Constructor called
delete called
Destructor called
#include<iostream>
using namespace std;
class Point {
private:
int x, y;
publi
Point() : x(0), y(0) { }
Point& operator()(int dx, int dy);
void show() {cout << "x = " << x << ", y = " << y; }
};
Point& Point::operator()(int dx, int dy)
{
x = dx;
y = dy;
return *this;
}
int main()
{
Point pt;
pt(3, 2);
pt.show();
return 0;
}
A.
Compiler Error
B.
x = 2, y = 3
C.
x = 3, y = 2
A. Control Source
B. Control Wizard
C. Row Source
D. Control Margin