Skip to content

Basic 50+ Interview Questions of C++

Here we provide the Interview questions of C++ with some Multiple Choice Questions. It will help to crack the interview…

Basic Interview Questions of C++

What is the correct value to return to the operating system upon the successful completion of a program?

a) -1

b) 1

c) 0

d) Program do not return a value.

Ans c) 0


What is the only function all c++ programs must contain?

a) start()

b) system()

c) main()

d) program()

Ans c) main()


What punctuation is used to signal the beginning and end of code blocks?

a) {}

b) -> and

c) Begin and End

d) ( and )

Ans a) {}


What punctuation ends most lines of c++ code?

a) .

b) ;

c) :

d) ”

Ans b) ;


Which of the following is a correct comment?

a) */ Comments */

b) ** Comment **

c) /* Comment */

d) { Comment }

Ans c) /* Comment */


Which of the following is a correct comment?

a) float

b) real

c) int

d) double

Ans b) real


Which of the following is the correct operator to compare two variables?

a) :=

b) =

c) equal

d) ==

Ans d) ==

Read More >> Top 39 C++ Interview Questions


Interview Questions of C++ on Input Stream

Which operator is used for the input stream?

a) >

b) >>

c) <

d) <<

Ans b) >>


Where does a cin stop its extraction of data?

a) By seeing a blank space

b) By seeing (

c) By seeing a blank space & (

d) Mentioned

  Ans: a) By seeing a blank space 

Which is used to get the input during runtime?

a) cout

b) cin

c) coi

d) None of these

  Ans b): cin 

What is the output of this program?

#include <iostream>

using namespace std;

int main ()

{

int i;

court<< “please enter an integer value:”;

cin >> i+4;

return 0;

}

a) 73

b) your value +4

c) error

d) None of these

Ans c) error   

What is the output of this program?

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

int main ()

{

string mystr;

float price = 0;

int quantity = 0;

cout << “enter price: “;

getline (cin, mystr);

stringstream(mystr) >> price;

cout << ” Enter quantity: “;

getline (cin, mystr);

stringstream(mystr) >> quantity;

cout << “Total price: ” << price * quantity << endl;

return 0;

}

a) 50

b) Depends on the value you enter

c) error

d) None of these

Ans b: Depend on the value you enter   

What is the output of this program?

#include <iostream>

using namespace std;

int main()

{

char line[100];

cin.getline(line, 100, ‘t’);

cout << line;

return 0;

}

a) 100

b) t

c) It will print what we enter till character t is encountered in the input

d) None of these

  Ans c: It will print what we enter till character t is encountered in the input 

How many parameters are there in getline function?

a) 1

b) 2

c) 2 or 3

d) 3

Ans d: 3   

What can be used to input a string with blank space?

a) inline

b) getline

c) outline

d) None of these

  Ans b: getline 

When will the cin start processing of input?

a) After processing return key

b) By processing blank space

c) After pressing the return key & By pressing blank space

d) None of these

  Ans a: After processing return key 

Interview Questions of C++ on Formatting

Interview Questions of C++ on Formatting

Which is used for formatting purposes in c++?

a) Whitespace

b) Container

c) &

d) Vector

Ans a) Whitespace


How many spaces should be set in the default tab?

a) 1

b) 2

c) 3

d) 4

Ans d: 4


What can be improved by formatting the source code?

a) Memory

b) Address

c) User Interface

d) None of these

Ans c: User Interface


Choose the correct formatted code.

a) int a = 5;

b) int a=5

c) inte a =5;

d) None of these.

Ans a: int a = 5;


Which function allows you to set the minimum width for the next input?

a) Setfill

b) setw

c) setwidth

d) None of these

Ans b) setw


What is the output of this program?

#include <iostream>

using namespace std;

int main()

{

unsigned long x = 64;

court<<x<<oct<<x<<endl;

return 0;

}

a) 64100

b) 48

c) 345

d) None of these

Ans a) 64100


What is the use of the function “showbase”?

a) Indicate the base used

b) Indicate the variable

c) Indicate the base used & variable

d) None of these

Ans a) Indicate the base used


Interview Questions of C++ on File & Strings

Which operator is used to insert the data into file?

a) >>

b) <<

c) <

d) None of these

Ans b) <<


Which function is used to position back from the end of file object?

a) seekg

b) seekp

c) both seekg & seekp

d) None of these

Ans a) seekg


How many objects are used for input and output to a string?

a) 1

b) 2

c) 3

d) 4

Ans c) 3


What is the output of this program?

#include<iostream>

#include<fstream>

using namespace std;

int main()

{

ofstream outfile (“test.txt”);

for (int n = 0; n < 100; n++)

{

outfile << n;

outfile.close();

return 0;

}

a) done

b) error

c) runtime error

d) None of these

Ans a) done


What is the output of this program?

#include <iostream>

using namespace std;

int main()

{

int a = 100;

double b = 14;

cout << a;

cout << endl;

cout << b << endl << a*b;

endl (cout);

return 0;

}

a) 100

b) 14

c) 314

d) None of these

Ans d) None of these


Which member function is used to determine whether the stream object is currently associated with a file?

a) is_open

b) buf

c) string

d) None of these

Ans a) is_open


Which header file is used for reading and writing to a file?

a) #include<iostream>

b) #include<fstream>

c) #include<file>

d) None of these

Ans b) #include<fstream>


Interview Questions of C++ on String Class

How many types of representation are in the string?

a) 1

b) 2

c) 3

d) 4

Ans b) 2


What is the header file for the string class?

a) #include<ios>

b) #include<str>

c) #include<string>

d) None of these

Ans c) #include<string>


Which is used to return the number of characters in the string?

a) length

b) size

c) both size & length

d) None of these

Ans c) both size & length


What is the output of this program?

#include <iostream>

#include <cstring>

using namespace std;

int main()

{

char str1[10] = “Hello”;

char str2[10] = “world”;

char str3[10];

int len;

strcpy(str3, str1);

strcat(str1, str2);

len = strlen(str1);

court << len << endl;

return 0;

}

a) 5

b) 55

c) 11

d) 10

Ans d: 10


What is the output of this program?

#include <iostream>

#include <string>

using namespace std;

int main ()

{

string str (“Microsoft”);

for (size_t i=0; I<str.length();)

{

cout <<str.at(i-1);

}

return 0;

}

a) M

b) Microsoft

c) Micro

d) runtime error

Ans d) runtime error


Which method do we use to append more than one character at a time?

a) append

b) operator+=

c) data

d) both append & operator+=

Ans d) both append & operator+=


Interview Questions of C++ on Objects

Where does the object is created?

a) Class

b) Constructor

c) Destructor

d) Attributes

Ans a) class


How to access the object in the class?

a) Scope resolution operator

b) Ternary operator

c) Direct member access operator

d) None of these

Ans c) Direct member access operator


Which of these following members are not accessed by using a direct member access operator?

a) Public

b) Private

c) Protected

d) Both private & protected

Ans d) Bith private & protected


Pick out the other definition of objects.

a) member of the class

b) associate of the class

c) attribute of the class

d) Instance of the class

Ans d) Instance of the class


How many objects can be present in a single class?

a) 1

b) 2

c) 3

d) as many as possible

Ans d) as many as possible


Which special character is used to mark the end of class?

a) ;

b) :

c) #

d) $

Ans a) ;


What is the output of this program?

#inclide <iostream>

using namespace std;

class number

{

int i;

public:

int geti();

void put(int j);

};

int number::geti()

{

return I;

}

void number::puti(int j)

{

i=j;

}

int main()

{

number s;

s.puti(10);

cout << s.geti();

return 0;

}

a) 10

b) 11

c) 20

d) 22

Ans a) 10


Interview Questions of C++ on Boolean

Is a bool a fundamental data type in c++?

a) yes

b) No, it is a typedef of unsigned char

c) No, it is an enum of {false, true}

d) No, it is expanded from macros

Ans a) yes


find the odd one out:

a) std::vector<int>

b) std::vector<short>

c) std::vector<long>

d) std::vector<bool>

Ans d) std::vector<bool>


What is the value of the bool?

bool is_int(789.54)

a) true

b) false

c) 1

d) None of these

Ans b) false


what happens when a null pointer is converted into bool?

a) an error is flagged

b) bool value evaluates to true

c) bool value evaluates to false

d) the statement is ignored

Ans c) bool value evaluates to false.


Which of the following statements are false?

a) bool can have two values and can be used to express logical expressions.

b)  bool cannot be used as the type of the result of the function

c) bool can be converted into integers simplicity

d) a bool value can be used in an arithmetic expression.

Ans b) bool cannot be used as the type of the result of the function.


For what values of the expression is an if-statement block not executed?

a) 0 and all negative values

b) 0 and -1

c) 0

d) 0, all negativity value, all positive values except 1

Ans c) 0


Which of the two operators++ and — work for the bool data type in c++?

a) ++ & —

b) ++

c) —

d) None

Ans b) ++


What is the output of the following program?

#include <iostream>

using namespace std;

int main()

{

int p;

bool a = true;

bool b = false;

int x = 10;

int y=5;

p = ((x|y) + (a+b));

cout<<p;

return 0;

}

a) 0

b) 16

c) 12

d) 2

Ans b) 16


Interview Questions of C++ on Character Types

How many characters are specified in the ASCII scheme?

a) 64

b) 128

c) 256

d) None of these

Ans b) 128


Which of the following belongs to the set of character types?

a) char

b) wchar_t

c) only a

d) both wchar_t and char

Ans d) both wchar_t and char


What will be the output of this program?

#include<iostream>

using namespace std;

int main()

{

char c = 74;

court << c;

return 0;

}

a) A

b) N

c) J

d) I

Ans c) J


How do we represent a wide character of the form wchar_t?

a) L’a’

b) l’a’

c) L[a]

d) la

Ans a) L’a’


What is the output of this program?

#include <stdio.h>

int main()

{

char a = ‘\012’;

print(“%d”, a);

return 0;

}

a) Compiler error

b) 12

c) 10

d) Empty

Ans c) 10


In c++, what is the sign of character data type by default?

a) Signed

b) Unsigned

c) Implementation dependent

d) None of these

Ans c) Implementation dependent


Is the size of character literals different in C and C++?

a) Implementation defined

b) Can’t say

c) Yes, they are different

d) No, they are not different

Ans c) Yes, they are different


Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return?

a) 4

b) 1

c) Implementation dependent

d) Machine dependent

Ans b) 1


What constant defined in <climits> header returns the number of bits in a char?

a) CHAR_SIZE

b) SIZE_CHAR

c) BIT_CHAR

d) CHAR_BIT

Ans d) CHAR_BIT


Interview Questions of c++ on Pointers

What does the following statement mean?

int (*fp)(char*)

a) pointer to a pointer

b) pointer to an array of chars

c) pointer to function taking a char* argument and returns an int

d) functions taking a char* argument and returning a pointer to int

Ans c) pointer to function taking a char* argument and returns an int


The operator used for dereferencing or indirection is ____

a) *

b) &

c) ->

d) –>>

Ans a) *


Choose the right option

string* x,y;

a) x is a pointer to the string, y is a string

b) y is a pointer to a string, x is a string

c) both x and y are pointers to string types

d) None of these

Ans a) x is a pointer to the string, y is a string


Which one of the following is not a possible state for a pointer.

a) hold the address of the specific object

b) point one past the end of an object

c) zero

d) point to a tye

Ans d) Point to a tye


Which of the following is illegal?

int a = 100, b=200;

int *p = &a, *q = &b;

p=q;

a) b is assigned to a

b) p now points to b

c) a is assigned to b

d) q now points to a

Ans b) p now points to b


What is the output of this program?

#include<iostream>

using namespace std;

int main()

{

int a =5, b=10, c=15;

int *arr[] = {&a, &b, &c};

court << arr[1];

return 0;

}

a) 5

b) 10

c) 15

d) It will return some random number

Ans d) It will return some random number.


What is the output of this program?

#include <iostream>

using namespace std;

int main()

{

char *ptr;

char Str[] = “abcdefg”;

ptr = Str;

ptr+ = 5;

court << ptr;

return 0;

}

a) fg

b) cdef

c) defg

d) abcd

Ans a) fg


If you have any doubt related to this interview questions of C++ ask me in the comment section…

Also-Read: 30+ Frequently Asked Interview Questions on Java

Leave a Reply

Your email address will not be published.

%d bloggers like this: