C++ Programming Multiple Choice Question - Overloading

This section focuses on the "Overloading" 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. Which is the correct statement anout operator overloading in C++?.

A. Only arithmetic operators can be overloaded
B. Associativity and precedence of operators does not change
C. Precedence of operators are changed after overlaoding
D. Only non-arithmetic operators can be overloaded

View Answer


2.Which of the following operators cannot be overloaded?

A. .* (Pointer-to-member Operator )
B. :: (Scope Resolution Operator)
C. .* (Pointer-to-member Operator )
D. All of the above

View Answer


3.While overloading binary operators using member function, it requires ___ argument?

A. 2
B. 1
C. 0
D. 3

View Answer


4.Which of the following operators should be preferred to overload as a global function rather than a member method?

A. Postfix ++
B. Comparison Operator
C. Insertion Operator <<
D. prefix ++

View Answer


5. Which of the following operator functions cannot be global, i.e., must be a member function.

A. new
B. delete
C. Converstion Operator
D. All of the above

View Answer


6. Which of the following is correct option?

         
#include<iostream>
using namespace std;
 
class lfc {
private:
  int x, y;
public:
  lfc() : x(0), y(0) { }
  lfc& operator()(int a, int b);
  void show() {cout << "x = " << x << ", y = " << y; }
};
 
lfc& lfc::operator()(int a, int b)
{
    x = a;
    y = b;
    return *this;
}
 
int main()
{
  lfc l;
  l(5, 10);
  l.show();
  return 0;
}

A. x = 5, y = 10
B. x = 10, y = 5
C. Compile Error
D. x = 5, y = 5

View Answer


7. Which of the following is correct option?

         
#include<iostream>
using namespace std;
 
class lfc {
private:
  int x, y;
public:
  lfc() : x(0), y(0) { }
  lfc& operator()(int a, int b);
  void show() {cout << "x = " << x << ", y = " << y; }
};
 
lfc& lfc::operator()(int a, int b)
{   
   x=a/b;
   y=b*x;
}
 
int main()
{
  lfc l;
  l(15, 5);
  l.show();
  return 0;
}

A. x = 15, y = 3
B. x = 3, y = 15
C. Compile Error
D. x = 15, y = 15

View Answer


8. Which of the following is correct option?

         
#include<iostream>
using namespace std;
class lfc1
{
    int y;
};
 
class lfc
{
    int x;
    lfc1 l2;
public:
    operator lfc1 ()  { return l2; }
    operator int () { return x; }
};
 
void lets ( int x) { cout << "lets(int) called"; }
void lets ( lfc1 l ) { cout << "lets(lfc 2) called"; }
 
int main()
{
    lfc l;
    lets(l);
    return 0;
}

A. lets(int) called
B. lets(lfc 2) called
C. Compiler Error: Ambiguous call to lets()
D. No error and No output

View Answer


9. Which of the following is the correct order involves in the process of operator overloading.
i) Define the operator function to implement the required operations.
ii) Create a class that defines the data type that is to be used in the overloading operation.
iii) Declare the operator function op() in the public part of the class.

A. 1-i, 2-ii, 3-iii
B. 1-ii, 2-iii, 3-i
C. 1-ii, 2-i, 2-iii
D. 1-iii, 2-ii, 3-i

View Answer


10. Which of the following is correct option?

         
#include<iostream>
using namespace std;
class LFC
{
    int i;
public:
    LFC(int ii = 0) : i(ii) {}
    void fun1() {  cout << i << endl;  }
};
 
class LFC1
{
    int x;
public:
    LFC1(int xx) : x(xx) {}
    operator LFC() const {  return LFC(x); }
};
 
void fun(LFC l)
{
    l.fun1();
}
 
int main()
{
    LFC1 l1(8);
    fun(l1);
    fun(10);
    return 0;
}

A. Compiler Error
B. 8
   10
C. 8
   8
D. 10
   8

View Answer






Also check :


Discussion


* You must be logged in to add comment.