Overloading In C++ Mcq Exercise 1 - C++ Programming Tutorial
C++ Course / MCQ & Exercises / Overloading In C++ Mcq Exercise 1

Overloading In C++ Mcq Exercise 1

BLUF: Mastering Overloading In C++ Mcq Exercise 1 is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Overloading In C++ Mcq Exercise 1

C++ is renowned for its efficiency. Learn how Overloading In C++ Mcq Exercise 1 enables low-level control and high-performance computing in the tutorial below.

  1. What is the motive for overloading the subscript operator in a class?
  • To access class members using index notation.
  • To perform arithmetic operations.
  • To concatenate strings.
  • To overload assignments.

Explanation:

The correct answer is option (a). The subscript operator is typically overloaded to permit entry to elements of a container class using index notation.

  1. Which of the following statement is correct about the overloading of the function call operator ?
  • It cannot be overloaded.
  • It must be a friend function.
  • It allows objects to be used as functions.
  • It can only be overloaded in derived classes.

Explanation:

The correct answer is option (c). The function call operator can be overloaded to allow objects to be used even though they were features.

  1. Which of the following operators can be overloaded in C++?
  • sizeof
  • . (dot operator)

Explanation:

The accurate choice is alternative (c). In C++, the + operator is capable of being overloaded. Operators like ::, sizeof, and . are not overloadable.

  1. What is the process for overloading the prefix increment operator ++ in a class?
Example

class A {

public:

    A& operator++();

};
  • A operator++(int);
  • A& operator++;
  • A& operator++(int);
  • void operator++;

Explanation:

The accurate choice is alternative (b). The prefix increment operator ++ is redefined as a member function that provides a reference to the class type.

How should a friend function be declared in C++ to overload the binary + operator correctly?

Example

class A {

    int value;

public:

    A(int v) : value(v) {}

    friend A operator+(const A&, const A&);

};
  • A operator+(A, A);
  • A operator+(const A&, const A&);
  • A operator+(A&);
  • A operator+(const A&);

Explanation:

The accurate choice is alternative (b). The auxiliary function for overloading the addition operator should be defined with two parameters passed by constant reference.

  1. Which of the subsequent instances demonstrates proper function overloading?
Example

void print(int i);

void print(double f);
  • Both
  • None of the above

Explanation:

Option (a) is the accurate choice. The print(int) and print(double) functions share identical names but differ in parameter types, exemplifying function overloading.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience