top of page
  • Facebook
  • Twitter
  • Instagram

Top C-plus-plus Interview Questions

Mobiprep handbooks are free downloadable placement preparation resources that can help you ace any company placement process. We have curated a list of the 40 most important MCQ questions which are asked in most companies such as Infosys, TCS, Wipro, Accenture, etc. The placement handbooks also have detailed explanations for every question ensuring you revise all the questions with detailed answers and explanations.

Question

33

Explanation

Differentiate between constructors and member functions.

1. Constructor name must be same as class name but functions cannot have same name as class name.
2. Constructor does not have return type whereas functions must have.
3. Member function can be virtual, but, there is no concept of virtual constructor in C++.
5. Constructors are invoked at the time of object creation automatically and can be called explicitly but functions are called explicitly using class objects.

Question

34

Explanation

What are destructors in C++?

A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class.
A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc.
SYNTAX:
~ClassName()
{
Statements..
…..
}

Question

35

Explanation

What is the output of the following program?

#include<iostream>

using namespace std;
void RootWorkz() {
static int i;

++i;
cout<<i<<" ";
}

main() {
RootWorkz();
RootWorkz();
RootWorkz();
}

The output of the following program will be:

1 2 3

This is because a static local variable retains its value between the function calls and the default value is 0.

Question

36

Explanation

What will be the output of the following program?

#include<iostream>

using namespace std;
void swap(int P, int Q) {
int x = P;

P = Q;
Q = x;
}
main() {
int x = 5, y = 3;

swap(x,y);
cout<<x<<" "<<y;
}

The output of the following program will be:

5 3

The values of x and y will not be swapped because call by value mechanism can’t alter actual arguments.

bottom of page