Back-End Programming Exam  >  Back-End Programming Tests  >  Test: Function - 2 - Back-End Programming MCQ

Test: Function - 2 - Back-End Programming MCQ


Test Description

15 Questions MCQ Test - Test: Function - 2

Test: Function - 2 for Back-End Programming 2024 is part of Back-End Programming preparation. The Test: Function - 2 questions and answers have been prepared according to the Back-End Programming exam syllabus.The Test: Function - 2 MCQs are made for Back-End Programming 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Function - 2 below.
Solutions of Test: Function - 2 questions in English are available as part of our course for Back-End Programming & Test: Function - 2 solutions in Hindi for Back-End Programming course. Download more important topics, notes, lectures and mock test series for Back-End Programming Exam by signing up for free. Attempt Test: Function - 2 | 15 questions in 40 minutes | Mock test for Back-End Programming preparation | Free important questions MCQ to study for Back-End Programming Exam | Download free PDF with solutions
Test: Function - 2 - Question 1

Predict output of the following program

#include<iostream>
using namespace std;
 
class Base
{
public:
    virtual void show() { cout<<" In Base n"; }
};
 
class Derived: public Base
{
public:
    void show() { cout<<"In Derived n"; }
};
 
int main(void)
{
    Base *bp = new Derived;
    bp->show();
 
    Base &br = *bp;
    br.show();
 
    return 0;
}

Detailed Solution for Test: Function - 2 - Question 1

Since show() is virtual in base class, it is called according to the type of object being referred or pointed, rather than the type of pointer or reference.

Test: Function - 2 - Question 2

Where does the return statement returns the execution of the program?

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Function - 2 - Question 3

Which of the following is true about pure virtual functions?
1) Their implementation is not provided in a class where they are declared.
2) If a class has a pure virtual function, then the class becomes abstract class and an instance of this class cannot be created.

Test: Function - 2 - Question 4

Overloaded functions are

Test: Function - 2 - Question 5

Predict the output of following program.

#include<iostream>
using namespace std;
class Base
{
public:
    virtual void show() = 0;
};
 
class Derived : public Base { };
 
int main(void)
{
    Derived q;
    return 0;
}

Detailed Solution for Test: Function - 2 - Question 5

If we don't override the pure virtual function in derived class, then derived class also becomes abstract class.

Test: Function - 2 - Question 6

When our function doesn’t need to return anything means what we will as parameter in function?

Test: Function - 2 - Question 7

Can a constructor be virtual? Will the following program compile?

#include <iostream>
using namespace std;
class Base {
public:
  virtual Base() {}  
};
int main() {
   return 0;
}

Detailed Solution for Test: Function - 2 - Question 7

There is nothing like Virtual Constructor. Making constructors virtual doesn't make sense as constructor is responsible for creating an object and it can’t be delegated to any other object by virtual keyword means.

Test: Function - 2 - Question 8

To which does the function pointer point to?

Test: Function - 2 - Question 9

What is the output of the program?

#include<iostream>
using namespace std;
class Base  {
public:
    Base()    { cout<<"Constructor: Base"<<endl; }
    virtual ~Base()   { cout<<"Destructor : Base"<<endl; }
};
class Derived: public Base {
public:
    Derived()   { cout<<"Constructor: Derived"<<endl; }
    ~Derived()  { cout<<"Destructor : Derived"<<endl; }
};
int main()  {
    Base *Var = new Derived();
    delete Var;
    return 0;
}

Detailed Solution for Test: Function - 2 - Question 9

Since the destructor is vitrual, the derived class destructor is called which in turn calls base class destructor.

Test: Function - 2 - Question 10

What is the default calling convention for a compiler in c++?

Test: Function - 2 - Question 11

Predict the output of following C++ program. Assume that there is no alignment and a typical implementation of virtual functions is done by the compiler.

#include <iostream>
using namespace std;
 
class A
{
public:
    virtual void fun();
};
 
class B
{
public:
   void fun();
};
 
int main()
{
    int a = sizeof(A), b = sizeof(B);
    if (a == b) cout << "a == b";
    else if (a > b) cout << "a > b";
    else cout << "a < b";
    return 0;
}

Detailed Solution for Test: Function - 2 - Question 11

Class A has a VPTR which is not there in class B. In a typical implementation of virtual functions, compiler places a VPTR with every object. Compiler secretly adds some code in every constructor to this.

Test: Function - 2 - Question 12

which of the following can be passed in function pointers?

Test: Function - 2 - Question 13

If the user didn’t supply the user value means, then what value will it take?

Detailed Solution for Test: Function - 2 - Question 13

If the user didn’t supply the value means, the compiler will take the given value in the argument list.

Test: Function - 2 - Question 14

Which value will it take when both user and default values are given?

Detailed Solution for Test: Function - 2 - Question 14

The default value will be used when the user value is not given, So in this case, the user value will be taken.

Test: Function - 2 - Question 15

If we start our function call with default arguments means, what will be proceeding arguments?

Detailed Solution for Test: Function - 2 - Question 15

As a rule, the default argument must be followed by default arguments only.

Information about Test: Function - 2 Page
In this test you can find the Exam questions for Test: Function - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Function - 2, EduRev gives you an ample number of Online tests for practice
Download as PDF