Top C++ Placement Questions and Answers

Updated: Jun 15

Following is the top C++ Placement MCQ questions and answers to help you crack best company placements.


Basic C++ Placement Questions


Q1. Which of the following is the actual name of C++?

  • C sharp

  • C extended

  • C with classes

  • C actual

Correct Answer: C

Explanation: It is initially called C with classes which later renamed as C++, which means increment C by 1


Q2. As of date, how many editions/versions of C++ are seen as of year 2015 :

  • 4 editions

  • 10 editions

  • 6 editions

  • 3 editions

Correct Answer: A

Explanation:

The versions of C++ are as follows:

C++98 - 1998, C++03 - 2003, C++11 - 2011, C++14 - 2014, C++17 - 2017


Q3. What is the value of p in the given code snippet.












  • 4

  • Error in compilation

  • 10

  • 5

Correct Answer: A

Explanation:

The expression is evaluated from right to left, as / %* stand relatively above in operator priority list than any other operator, thus (k*2/3%10) is executed first writing the value as 0.As the value of k<<2 is 4, the output of the final expression is 4+0, i.e., 4


Q4. C++ was developed by :

  • Dennis Ritchie

  • James Gosling

  • Guido van Rossum

  • Bjarne Stroustrup

Correct Answer: D

Explanation:

Dennis Ritchie – Father of C,

James Gosling – Developer of Java,

Guido van Rossum – Python developer


Q5. What is the output of given code snippet?








  • 0

  • 6

  • 10

  • 6

Correct Answer: C

Explanation:

In the declaration of j, --i refers to decrement of i value by 1 and ++i refers to increment of i value by 1 and thus j takes the value 10.


Q6. What is size of int(integer) data type in c++?

  • 6 Bytes

  • 8 Bytes

  • 2 Byte

  • Depends on Compiler


Correct Answer: D

Explanation:

If it is 16 bits compiler like Turbo C++, the size is 2 bytes while if it is 32 bit compiler like Dev-C++, g++ or Visual Studio, the size is 4 bytes.


Q6. Select the proper execution process of a program in C++ language from the following

  • Source Code -> Compiler -> Object code -> Linker -> Machine code -> (OS+CPU)

  • Source code -> compiler -> Byte code -> Virtual Machine

  • Source code -> compiler -> Byte code -> Interpreted by VM

  • All of the above


Correct Answer: A

Explanation:

Option b refers to Java and option c refers to python


Q7. How many object can be created of a Class in C++?

  • At most 8

  • No limit

  • 32

  • 16


Correct Answer: B

Explanation:

One can instantiate any number of objects for a given class.


Q8. Select a proper statement.

  • One cannot create his own workspace.

  • a class can contain another class in it

  • int a(10) is a different declaration from int a=10;

  • One can reinitialize a reference variable

Correct Answer: B

Explanation:

Int a(10) and int a=10 are same declarations, One can never reinitialize a reference variable as it might lead to memory corruption.

One can always create his own workspace by following the given procedure:




Q9. Which is not an integer data type?

  • Byte

  • Single

  • Short

  • Integer

Correct Answer: B

Explanation:

Different types of int in c++ are as follows: Unsigned int, signed int, short int, unsigned short int, signed short int, long int, signed long int, Unsigned long int, long long int, unsigned long long int, int.


10. Select the correct option with respective to the following code snippet.











  • Welcome to Rootworkz Learning

  • We are from RootWorkz learning

  • Compilation Error

  • No output


Correct Answer: B

Explanation:

In C++ programming, 0 is false 1 is true and thus if(0) evaluates false condition


Q11.How many times "RootWorkz Learning" is printed?



  • 0 times

  • Error in execution

  • 5 times

  • 4 times


Correct Answer: C

Explanation:

The if condition evaluates i<5 value as true for i value from 0 to 4, and false when i takes the value i=5.


Q12. What is the value of rwl in below program?

  • Hello from RootWorkz Learning

  • No output as it is not a true condition

  • Compilation Error

  • The program will not be executed


Correct Answer: A

Explanation:

Value of rwl is 90/20 and thus 4.5.Since, rwl is of int type, the 4.5 is truncated to 4


Q13 ? , ternary operator, is used in substitute of :

  • For loop

  • Switch case

  • If statement

  • No such operator exists


Correct Answer: C

Explanation:

Also called as short-hand if.


Q14. Select the inappropriate statement with respective to the code snippet.

  • Outputs It is a E-Learning platform

  • ? is used as substitute of if condition

  • No output as there is no such ? operator.

  • Option a, b are correct

Correct Answer: C

Q15. What is correct syntax of for loop?

  • for(initialization; condition; increment/decrement)

  • for(increment/decrement; initialization; condition)

  • for(initialization, condition, increment/decrement

  • None of These

Correct Answer: A


Intermediate C++ Placement Questions:


Q16. Can a switch statement be nested?

  • No

  • Yes


Correct Answer: B

Explanation:

Nested switch can be achieved by writing a switch statement in any case of a already called switch statement.


Q17. What is the purpose of loops?

  • They save time, reduce errors, and they make code more readable.

  • To perform operations on variables and values.

  • It can also be used to prevent execution when testing alternative code.

Correct Answer: A


Q18. How many times the statement RootWorkz Learning does get printed?

//<image missing>//

  • 0 times

  • 99 times

  • 100 times

  • 101 times

Correct Answer: C

Explanation:

While loop takes I value from 0 to 99, and exists the loop for i=100


Q19. Select the appropriate statement in regard with the code snippet.

//<image missing>//

  • Prints the values from 0 to 5 excluding 5.

  • Prints the values from 0 to 5 including 5.

  • Infinite loop

  • Compilation error

Correct Answer: C

Explanation:

As there no increment to the value of i, the above loop turns out to be an infinite loop.


Q20. What is output of below program?

//<image missing>//

  • Error

  • 111111

  • 101011

  • 101010

Correct Answer: A

Explanation:

As their no variables initialized with the names x,p


Q21. Which of the following is assignment operator?

  • =

  • ==

  • >>

  • <=

Correct Answer: A

Explanation:

== is called as Equality operator, >> is Left Shift operator, <= is called Lesser than or equal to


Q22. Which operator has more precedence among the following?

*

++

+

-

  • ++

  • *

  • +

Correct Answer: A

Explanation:


Q23. How many types of operators are in C++?

  • 3

  • 4

  • 5

  • 6

Correct Answer: C

Explanation:

The 5 types of operators in C++ are as follows: Arithmetic, Assignment, Comparison, Logical and Bitwise operators


Q24. && is what kind of operator.

  • Bitwise operator

  • Assignment operator

  • Comparison operator

  • Logical operator

Correct Answer: D

Explanation:

&& - also called as Logical and operator.


Q25. How many ways a user can comment a piece of code?

  • 3

  • 1

  • There is no way one can comment in C++

  • 2

Correct Answer: B

Explanation:

There are 2 ways one can comment in C++:

  1. Single-line comment using //

  2. Multi-line comment using /**/


Advanced C++ Placement Questions:


Q26. How many different types a variable can be assigned with?

  • 3

  • 4

  • 5

  • 6

Correct Answer: C

Explanation:

5 types – int, double, string, char, bool


Q27. What is the output expected for the below code snippet.

//<image missing>//

  • Welcome

  • Welcome to RootWorkz Learning

  • Does not execute

  • None of the above

Correct Answer: B

Explanation:

The switch case start with the case 1 and exits the loop after executing the case 4 as there is break statement.


Q28. How does one perform complex math functions like logarithmic, exponential in C++?

  • One cannot perform such functions in C++

  • By including cmath library.

  • By writing detailed code for it

  • None of the above

Correct Answer: B

Explanation:

cmath is a library that has many functions which allows one to perform many mathematical tasks.


Q29. Select the appropriate statement from the following in regard break, continue keywords.

  • There is no difference, those are just 2 keywords used for same functionality

  • breaks particular iteration, continue doesn’t harm any iteration

  • There are no such keywords named break, and continue.

  • Continue is used to break an iteration, break is used to jump off particular loop.

Correct Answer: D

Explanation:

Self – explanatory.


Q30. What is an array in C++.

  • Creates a data type that can be used to group items of possibly different types into a single type

  • They provide an efficient way of using the same memory location for multiple purposes.

  • Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.

  • None of the above

Correct Answer: C

Explanation:

Option a refers to structure in c++, option b refers to union in c++.


Q31. Explain the concept of pointers and references in C++?

  • There is no difference, those are just 2 keywords used for same functionality.

  • There is no concept of references in C++

  • There is no concept of pointers in C++

  • References are used to refer an existing variable in another name whereas pointers are used to store address of variable.

Correct Answer: D

Explanation:

Self-explanatory


Q32. Which of the following pair best fits the (x,y) pair in the given declaration

x array [ y ];

  • int, -10

  • long , 4.5

  • Double , 5

  • double, 15


Correct Answer: D

Explanation:

x refers to data type, y refers to array-size. There is no such type with the keyword Double


Q33. In C++, how do you find number of elements in a given array arr.

  • By using keyword arr.length()

  • By using keyword arr.length()

  • sizeof(arr)

  • sizeof(arr) / sizeof(arr[0])


Correct Answer: D

Explanation:

Number of elements in an array refers to length of the array. There is no such keyword called arr.length() and arr.lengthsizeof(arr) refers to total memory size of array, and thus to find number of elements ratio between total array size and size of each element gives out number of elements


Q34. Select the odd one out.

  • Array considers homogeneous type elements only.

  • The pointer variable must be declared with the type to which it is referring to.

  • Increment and decrement operations cannot be performed on pointers

  • Void pointer is a pointer that has no associated data type with it.

Correct Answer: C

Explanation:

Above all are the correct statements other than the answer (marked).


Q35. What is the output for the following code snippet?

//<image missing>//

  • Compilation Error – Constructor Missing

  • Nothing is printed

  • Undefined

  • Error: Improper object instantiation

Correct Answer: B

Explanation:

A class can be empty, thus there can be no error.


Q36. Select the odd one out.

  • A class can be nested

  • A singleton class can have at most 1 object.

  • Constructor is a special type of function used for declarations

  • C++ does not support the concept of nested class.

Correct Answer: D

Explanation:

All the above statements are true other than the answer, i.e., C++ do support nested classes.


Q37. How many different constructors are possible in C++

  • 3

  • 1

  • 0

  • There is no concept called Constructors in C++


Correct Answer: A

Explanation:

Default, parameterized, copy are the different types of constructors in C++


Q38. Methods in C++ is similar to which concepts of C.

  • Functions

  • Switch case

  • Data structures

  • None of the above

Correct Answer: A

Explanation:

Self – explanatory


Q39. DRY feature of coding is supported by which concept of C++.

  • a) OOP

  • b) Exception Handling

  • c) Pointers

  • d) Arrays

Correct Answers: A

Explanation:

DRY means Don’t Repeat Yourself, which means the feature of code reusability. OOP concepts are the ones which support the concept of code reusability.




 

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 with detailed explanations to ensure the best placement preparation.

Top 40 C++ Interview questions
.pdf
Download PDF • 1.18MB




 

297 views0 comments

Recent Posts

See All