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

5

Explanation

What is inline function? Explain with an example.

Inline functions are the functions which are not actually called, rather their code is expanded in line at the point of each invocation.
> The process is similar to using a function-like macro.
> The definition of the function should be preceded with the inline‘ keyword in order for it to be an inline function.
> Inline functions are important because they allow us to create very efficient code.
> Expanding function calls in line can produce faster run times.
> The significant amount of overhead which is generated by the calling and return mechanism can be reduced.
Example:

#include<iostream>
Using namespace std;
Inline int max( int a, int b)
{
return a>b ? a : b ;
}
int main()
{
cout << max (10,20);
cout << max ( 99, 98 );
return 0;
}

Question

6

Explanation

Explain continue statement with an example.

The continue statement forces the next iteration of the loop to take place, skipping any code in between.
>For the for loop, continue causes the conditional test and increment portions of the loop to execute.
>For the while and do-while loops, program control passes to the conditional tests.
The following program shows the use of continue statement:

void code ( void )
{
char done, ch;
done = 0;
while (! done)
{
ch = getchar ( );
if ( ch = = ‗$‘) {
done = 1;
continue;
}
putchar ( ch + 1);
}
}

The break statement has two uses:
>We can use it to terminate a case in the switch statement.
>We can use it to force immediate termination of a loop, by passing the normal conditional test.
When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop
Example:
# include <iostream.h>
void main()
{ int i=0;
while(i<=10)
{
cout<<i;
if (i==5)
break;
i++;
}
}

Question

7

Explanation

Define #define and const.

#define :
The #define directive is a preprocessor directive. The preprocessor replaces those macros by their body before the compiler even sees it. Think of it as an automatic search and replace of your source code.
Example: #define PI 3.14

const :
A const variable declaration declares an actual variable in the language, which you can use like a real variable: It take its address, pass it around, use cast it, convert it, etc.
Exampe: const float PI=3.14;

Difference B/W const and #define
1.const means the data can't be changed while define has no such meaning.
2.const is used by compiler and define is performed by preprocessor.
3.const has scope while define can be considerd global.
4.const variable can be seen from debugger while macro can be seen.

Question

8

Explanation

What do you mean by enumerated constants or enums?

An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.
The syntax for enumerated constants is to write the keyword enum, followed by the type name, an open brace, each of the legal values separated by a comma, and finally a closing brace and a semicolon.
For Example:
enum COLOR { RED, BLUE, GREEN, WHITE, BLACK };
This statement performs two tasks:
1. It makes COLOR the name of an enumeration, that is, a new type.
2. It makes RED a symbolic constant with the value 0, BLUE a symbolic constant with the value 1, GREEN a symbolic constant with the value 2, and so forth.

bottom of page