250+ TOP MCQs on Function Call and Answers

This section on C++ quiz on “Function Call”. One shall practice these quizzes to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ quiz comes with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ quiz on “Function Call” along with answers, explanations and/or solutions:

1. What is the use of function call operator?
a) overloading the methods
b) overloading the objects
c) overloading the parameters
d) overloading the string
Answer: b
Clarification: Overloading the objects is the use of function call operator.

2. Pick out the correct statement.
a) virtual functions does not give the ability to write a templated function
b) virtual functions does not give the ability to rewrite a templated function
c) virtual functions does give the ability to write a templated function
d) virtual functions does not give the ability to rewrite a simple function
Answer: a
Clarification: Virtual functions does not give the ability to write a templated function.

3. What will happen when the function call operator is overloaded?
a) It will not modify the functions
b) It will modify the functions
c) It will modify the object
d) It will modify the operator to be interpreted
Answer: d
Clarification: It will modifies how the operator is to be interpreted when applied to objects of a given type.

4. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     class Distance
  4.     {
  5.         private:
  6.         int feet;
  7.         int inches;
  8.         public:
  9.         Distance()
  10.         {
  11.             feet = 0;
  12.             inches = 0;
  13.         }
  14.         Distance(int f, int i) 
  15.         {
  16.             feet = f;
  17.             inches = i;
  18.         }
  19.         Distance operator()(int a, int b, int c)
  20.         {
  21.             Distance D;
  22.             D.feet = a + c + 10;
  23.             D.inches = b + c + 100 ;
  24.             return D;
  25.         }
  26.         void displayDistance()
  27.         {
  28.             cout  << feet <<  inches << endl;
  29.         }
  30.     };
  31.     int main()
  32.     {
  33.         Distance D1(11, 10), D2;
  34.         cout << "First Distance : ";
  35.         D1.displayDistance();
  36.         D2 = D1(10, 10, 10);
  37.         cout << "Second Distance :";
  38.         D2.displayDistance();
  39.         return 0;
  40.     }

a)

   First Distance : 1110
   Second Distance :30120

b)

   First Distance : 110
   Second Distance :3020

c)

   First Distance : 1115
   Second Distance :30125

d) pre> First Distance : 100
Second Distance :30120
Answer: a
Clarification: We are calculating the foot and inches by using the function call operator.
Output:

$ g++ call.cpp
$ a.out
First Distance : 1110
Second Distance :30120

 
 

5. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     void duplicate (int& a, int& b, int& c)
  4.     {
  5.         a *= 2;
  6.         b *= 2;
  7.         c *= 2;
  8.     }
  9.     int main ()
  10.     {
  11.         int x = 1, y = 3, z = 7;
  12.         duplicate (x, y, z);
  13.         cout << x << y << z;
  14.         return 0;
  15.     }

a) 1468
b) 2812
c) 2614
d) 2713
Answer: c
Clarification: We are passing the values by reference and modified the data on the function block.
Output:

$ g++ call1.cpp
$ a.out
2614

6. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     class three_d 
  4.     {
  5.         int x, y, z;
  6.         public:
  7.         three_d() { x = y = z = 0; }
  8.         three_d(int i, int j, int k) { x = i; y = j; z = k; }
  9.         three_d operator()(three_d obj);
  10.         three_d operator()(int a, int b, int c);
  11.         friend ostream &operator<<(ostream &strm, three_d op);
  12.     };
  13.     three_d three_d::operator()(three_d obj)
  14.     {
  15.         three_d temp;
  16.         temp.x = (x + obj.x) / 2;
  17.         temp.y = (y + obj.y) / 2;
  18.         temp.z = (z + obj.z) / 2;
  19.         return temp;
  20.     }
  21.     three_d three_d::operator()(int a, int b, int c)
  22.     {
  23.         three_d temp;
  24.         temp.x = x + a;
  25.         temp.y = y + b;
  26.         temp.z = z + c;
  27.         return temp;
  28.     }
  29.         ostream &operator<<(ostream &strm, three_d op) {
  30.         strm << op.x << ", " << op.y << ", " << op.z << endl;
  31.         return strm;
  32.     }
  33.     int main()
  34.     {
  35.         three_d objA(1, 2, 3), objB(10, 10, 10), objC;
  36.         objC = objA(objB(100, 200, 300));
  37.         cout << objC;
  38.         return 0;
  39.     }

a) 55, 106, 156
b) 55, 106
c) 55, 106, 159
d) 55, 106, 158
Answer: a
Clarification: In this program, We are using the function call operator to calculate the value of objc.
Output:

$ g++ call2.cpp
$ a.out
55, 106, 156