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

17

Explanation

What do you mean by static variables in C++? Write example program.

A static variable tells the compiler to persist the variable until the end of program. Instead of creating and destroying a variable every time when it comes into and goes out of scope, static is initialized only once and remains into existence till the end of program.

void test();
main()
{
test();
test();
test();
}
void test()
{
static int a = 0; //Static variable
a = a+1;
printf("%d\t",a);
}
Output : 1 2 3

Question

18

Explanation

Explain Storage classes in C++.

In C++ language, each variable has a storage class which decides scope, visibility and lifetime of that variable. The following storage classes
are most oftenly used in C++ programming:

1. Automatic variables: A variable declared inside a function without any storage class specification, is by default an automatic variable. They are created when a function is called and are destroyed automatically when the function exits.
Example:
void main()
{
int Arjun; or auto int Arjun;
}

2. External variables: A variable that is declared outside any function is a Global variable. Global variables remain available throughout the entire program.
Example:
int number; // global variable
void main()
{
number=10;
}
fun1()
{
number=20;
}
fun2()
{
number=30;
}


3. Static variables: A static variable tells the compiler to persist the variable until the end of program. Instead of creating and destroying a variable every time when it comes into and goes out of scope, static is initialized only once and remains into existence till the end of program.

4. Register variables: Register variable inform the compiler to store the variable in register instead of memory.

Question

19

Explanation

Explain functon overloading.

Defining multiple functions in a program having same name is called as function overloading. Only precaution to be taken is that function must have different no of or type of argument.
Compiler will decide which to call depending on no. of or type of arguments passed while calling the function.
Example:
# include<iostream.h>
int volume(int L, int B, int H)
{
int v=L*B*H;
return v;
}
int volume(int N)
{
int v=N*N*N;
return v;
}
void main()
{
int a=volume(5,7,8);
cout<<”Volume of box is “<<a;
int b=volume(5);
cout<<”Volume of cube is “<<b;
}

Question

20

Explanation

What do you mean by typedef in C++.

typedef is a keyword used to assign alternative names to existing types. Its mostly used with user defined data types, when names of data types get slightly complicated.
Syntax:
typedef existing_name alias_name

bottom of page