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

Test: Function - 1 - Back-End Programming MCQ


Test Description

15 Questions MCQ Test - Test: Function - 1

Test: Function - 1 for Back-End Programming 2024 is part of Back-End Programming preparation. The Test: Function - 1 questions and answers have been prepared according to the Back-End Programming exam syllabus.The Test: Function - 1 MCQs are made for Back-End Programming 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Function - 1 below.
Solutions of Test: Function - 1 questions in English are available as part of our course for Back-End Programming & Test: Function - 1 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 - 1 | 15 questions in 30 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 - 1 - Question 1

Which of the following is true about virtual functions in C++.

Test: Function - 1 - Question 2

What are mandatory parts in function declaration?

Detailed Solution for Test: Function - 1 - Question 2

In a function, return type and function name are mandatory all else are just used as a choice.

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

Output of 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, b;
    Derived d;
    bp = &d;
    bp->show();
    bp = &b;
    bp->show();
    return 0;
}

Detailed Solution for Test: Function - 1 - Question 3

Initially base pointer points to a derived class object. Later it points to base class object,

Test: Function - 1 - Question 4

How many max number of arguments can present in function in c99 compiler?

Test: Function - 1 - Question 5

What is the output of the program?

#include<iostream>
using namespace std;

class Base
{
public:
    virtual void show() = 0;
};

int main(void)
{
    Base b;
    Base *bp;
    return 0;
}

Detailed Solution for Test: Function - 1 - Question 5

Since Base has a pure virtual function, it becomes an abstract class and an instance of it cannot be created. So there is an error in line "Base b". Note that there is no error in line "Base *bp;". We can have pointers or references of abstract classes.

Test: Function - 1 - Question 6

What is the output of this program?

#include < iostream >
using namespace std;
void mani()
void mani()
{
cout << "hai";
}
int main()
{
main();
return 0;
}

Detailed Solution for Test: Function - 1 - Question 6

We have to use the semicolon to declare the function in line 3. If we did means, the program will execute.

Test: Function - 1 - Question 7

What is the output of the program?

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

Test: Function - 1 - Question 8

What is the scope of the variable declared in the user definied function?

Detailed Solution for Test: Function - 1 - Question 8

The variable is valid only in the function block as in other.

Test: Function - 1 - Question 9

Can a destructor 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 - 1 - Question 9

A destructor can be virtual. We may want to call appropriate destructor when a base class pointer points to a derived class object and we delete the object. If destructor is not virtual, then only the base class destructor may be called. For example, consider the following program.

Test: Function - 1 - Question 10

How many ways of passing a parameter are there in c++?

Detailed Solution for Test: Function - 1 - Question 10

There are three ways of passing a parameter. They are pass by value,pass by reference and pass by pointer.

Test: Function - 1 - Question 11

Can static functions be virtual? Will the following program compile?

#include<iostream> 
using namespace std;    

class Test
{
   public:
      virtual static void fun()  { }
};

Detailed Solution for Test: Function - 1 - Question 11

Static functions are class specific and may not be called on objects. Virtual functions are called according to the pointed or referred object.

Test: Function - 1 - Question 12

By default how the value are passed in c++?

Test: Function - 1 - Question 13

What is the output of the program?

#include <iostream>
using namespace std;
  
class A
{
public:
    virtual void fun() { cout << "A::fun() "; }
};
  
class B: public A
{
public:
   void fun() { cout << "B::fun() "; }
};
  
class C: public B
{
public:
   void fun() { cout << "C::fun() "; }
};
  
int main()
{
    B *bp = new C;
    bp->fun();
    return 0;
}

Detailed Solution for Test: Function - 1 - Question 13

The important thing to note here is B::fun() is virtual even if we have not uses virtual keyword with it. When a class has a virtual function, functions with same signature in all descendant classes automatically become virtual. We don't need to use virtual keyword in declaration of fun() in B and C. They are anyways virtual.

Test: Function - 1 - Question 14

How many types of returning values are present in c++?

Detailed Solution for Test: Function - 1 - Question 14

The three types of returning values are return by value, return by reference and return by address.

Test: Function - 1 - Question 15

Predict the output of following C++ 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->Base::show();  // Note the use of scope resolution here

    return 0;

}

Detailed Solution for Test: Function - 1 - Question 15

A base class function can be accessed with scope resolution operator even if the function is virtual.

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