×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

C++ MCQs (Multiple-Choice Questions)

C++ is a high-level, general-purpose computer programming language that supports all features of C language with the concepts of an object-oriented programming approach.

C++ Programming MCQs

C++ MCQs: This section contains multiple-choice questions and answers on the various topics of C++ Programming. Practice these MCQs to test and enhance your skills on C++ Programming.

List of C++ Multiple-choice Questions and Answers

1. C++ language was developed by ___.

  1. Dennis Rechard
  2. Dennis M. Ritchie
  3. Bjarne Stroustrup
  4. Anders Hejlsberg

Answer: C) Bjarne Stroustrup

Explanation:

C++ programming language was developed by Bjarne Stroustrup at Bell Laboratories (formerly AT&T Bell Laboratories).

Discuss this Question


2. In which year, the name of the language was changed from "C with Classes" to C++?

  1. 1979
  2. 1972
  3. 1983
  4. 1986

Answer: C) 1983

Explanation:

In 1983, the name of the language was changed from "C with Classes" to C++.

Discuss this Question


3. C++ language is a successor to which language?

  1. B
  2. C
  3. Java
  4. VB

Answer: B) C

Explanation:

C++ is a successor of C language.

Discuss this Question


4. C++ language is a ___.

  1. Object Oriented Language
  2. Procedural Oriented Language
  3. Structural Oriented Language
  4. None of the above

Answer: A) Object Oriented Language

Explanation:

C++ is an object-oriented language. It supports the concept of OOPs.

Discuss this Question


5. C++ follows ___.

  1. Top-Down Design approach
  2. Bottom-Up Design approach
  3. Both of the above
  4. None of the above.

Answer: B) Bottom-Up Design approach

Explanation:

C++ follows a bottom-up design approach for development.

Discuss this Question


6. C++ is a ___.

  1. High-level language
  2. Medium level language
  3. Low-level language
  4. None of the above

Answer: B) Medium level language

Explanation:

C++ is a medium-level language because it contains the features of low-level language as well as high-level language (Low-level Vs High-level).

Discuss this Question


7. How many keywords are in C++?

  1. 32
  2. 48
  3. 99
  4. 95

Answer: D) 95

Explanation:

Keywords are also known as reserved words, there are 95 keywords are available in C++. Some of the C++ keywords are not available in the C language.

Discuss this Question


8. Which of the following is not a valid keyword in C++ language?

  1. while
  2. for
  3. switch
  4. do-while

Answer: D) do-while

Explanation:

Do-while is a control statement, here "do" and "while" are different keywords.

Discuss this Question


9. Which of the following statement is correct about identifiers in C++?

  1. Identifiers are the combination of alphanumeric characters that can be used for function and variable names.
  2. Identifiers are a combination of alphanumeric characters that can be used for looping statements.
  3. Both of the above
  4. None of the above

Answer: A) Identifiers are the combination of alphanumeric characters that can be used for function and variable names.

Explanation:

The 2nd statement is correct about identifiers in C++.

Discuss this Question


10. Which of the following is used for single-line comment in C++?

  1. //
  2. \\
  3. /* */
  4. ##

Answer: A) //

Explanation:

We use "//" for single-line comments in C++.

Discuss this Question


11. Which of the following is used for multi-line comments in C++?

  1. //
  2. \\
  3. /* */
  4. ##

Answer: C) /* */

Explanation:

We use "/* */" for multi-line comment in C++.

Discuss this Question


12. In C++, can we put comments between the statement?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, we can put comments between the statement in C++ language.

C = A /*2+3*/ + B;

Discuss this Question


13. In which year C++14 was introduced?

  1. 2014
  2. 2015
  3. 2017
  4. None of the above

Answer: A) 2014

Explanation:

C++14 was introduced in 2014. It contains the following features:

  • polymorphic lambdas
  • digit separators
  • generalized lambda capture
  • variable templates
  • binary integer literals
  • quoted strings

Discuss this Question


14. Which of the following language translator is used in C++?

  1. Assembler
  2. Interpreter
  3. Compiler
  4. Both Interpreter and Compiler

Answer: C) Compiler

Explanation:

In C++, a Compiler is used to process C++ source files and generate object files.

Discuss this Question


15. Which of the following whitespace characters can be used in C++?

  1. Horizontal tab
  2. Vertical tab
  3. Form feed
  4. New line

Options:

  1. 1 and 2
  2. 3 and 4
  3. 1, 3, 4
  4. All 1,2,3,4

Answer: D) All 1,2,3,4

Explanation:

In C++, we can use the following whitespace characters:

  • Space
  • Horizontal tab
  • Vertical tab
  • Form feed
  • New-line

Discuss this Question


16. Which of the following is the correct extension of the C++ source code file?

  1. .cpp
  2. .c++
  3. Both
  4. None

Answer: c) Both

Explanation:

We can use both ".cpp" and ".c++" for a C++ source code file.

Discuss this Question


17. Which of the following command is used for the C++ compiler in Linux OS?

  1. GCC
  2. c++
  3. g++
  4. None

Answer: C) g++

Explanation:

The g++ command is used to compile C++ source files.

Discuss this Question


18. C++ is a pure object-oriented language.

  1. True
  2. False

Answer: B) False

Explanation:

C++ is not a pure object-oriented language because it supports the oops concept as well as procedural-oriented features.

Discuss this Question


19. C++ supports automatic garbage collection?

  1. True
  2. False

Answer: B) False

Explanation:

C++ does not support automatic garbage collection. Here we need to free dynamically allocated memory using free() or delete. Otherwise, it may cause memory leaks.

Discuss this Question


20. C++ is case sensitive language?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, C++ is a case-sensitive language. Here Var1 and var1 will treat differently.

Discuss this Question


21. Which of the following OOPs concepts are supported in C++?

  1. Inheritance
  2. Encapsulation
  3. Abstraction
  4. Polymorphism

Opation:

  1. 1 and 2
  2. 1, 2, and 3
  3. 1, 2, and 4
  4. All 1,2,3,4

Answer: D) All 1,2,3,4

Explanation:

C++ supports the following OOPS concept:

  1. Inheritance
  2. Encapsulation
  3. Abstraction
  4. Polymorphism

Discuss this Question


22. OOPs stands for?

  1. Object Oriented Process System
  2. Object Oriented Programming System
  3. Object Oriented Programming Service
  4. Object Orientation Programming System

Answer: B) Object Oriented Programming System

Explanation:

OOPs stands for Object Oriented Programming System.

Discuss this Question


23. Is it true, C++ is a superset of C language?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, C++ is known as a superset of C. Because C++ supports almost all the features of C language.

Discuss this Question


24. C++ is a more secure programming language compared to C language?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, C++ is a more secure programming language compared to C language because C language does not support encapsulation and information hiding.

Discuss this Question


25. Stream is ___.

  1. Group of non-printable character
  2. Sequence of bytes
  3. Set of errors
  4. The flow of invalid characters

Answer: A) Group of non-printable character

Explanation:

In C++, we use the stream concept for Input/Output operations. It is a sequence of bytes or flow of data that improves performance.

Discuss this Question


26. If the set of bytes flows from main memory to other devices like printers, the monitor is known as ___.

  1. Input Operation
  2. Output Operation
  3. Both of above
  4. None of the above

Answer: B) Output Operation

Explanation:

If the set of bytes flows from the main memory to other devices like the printer, the monitor is known as output operation.

Discuss this Question


27. Which of the following header file is used to define cin, cout?

  1. <iomanip.h>
  2. <iostream.h>
  3. <fstream.h>
  4. None of the above

Answer: B) <iostream.h>

Explanation:

The <iostream.h> header file is used to define cin and cout.

Discuss this Question


28. The cin, cout are ___.

  1. Library functions
  2. structures
  3. Pointers
  4. objects

Answer: D) objects

Explanation:

The cin and cout are the objects of the istream and ostream classes respectively that are used to perform input/output operations.

Discuss this Question


29. Which of the following is not a valid predefined object in C++?

  1. cin
  2. cout
  3. cput
  4. cerr

Answer: C) cput

Explanation:

The "cput" is not a valid predefined object in C++.

Discuss this Question


30. The stdout stands for ___.

  1. State Output
  2. Standard Output
  3. Stand Output
  4. Stream Output

Answer: B) Standard Output

Explanation:

The "stdout" stands for standard output. It is used to represent standard output devices like the monitor.

Discuss this Question


31. Is it true, the cerr is an object of the ostream class?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, it is true, the cerr is an object of the ostream class, which is used to output the errors.

Discuss this Question


32. Which of the following is an insertion operator in C++?

  1. <<
  2. >>
  3. ->
  4. <<<

Answer: A) <<

Explanation:

In C++, "<<" is known as the insertion operator which is used with the "cout" object to print data on the console screen.

Discuss this Question


33. Which of the following is an extraction operator in C++?

  1. >>>
  2. >>
  3. ->
  4. <<<

Answer: B) >>

Explanation:

In C++, ">>" is known as an extraction operator which is used with the "cin" object to read user input.

Discuss this Question


34. The endl is a ___.

  1. Macro
  2. object
  3. Pointers
  4. function

Answer: A) Macro

Explanation:

The endl is an object of ostream classes, which is used to print newline on the console screen.

Discuss this Question


35. Which of the following object is also used to flush the stream?

  1. cin
  2. cout
  3. cerr
  4. endl

Answer: D) endl

Explanation:

The "endl" object is used to print the newline as well as flush the stream.

Discuss this Question


36. Which of the following namespace contains cin, cout objects?

  1. ost
  2. std
  3. endl
  4. none of the above

Answer: B) std

Explanation:

The "std" namespace contains cin, and cout objects.

Discuss this Question


37. Which of the following are types of datatypes in C++?

  1. Basic Datatype
  2. Derived Datatype
  3. Enumeration data type
  4. User Defined datatype

Options:

  1. 1 and 2
  2. 1, 2, and 4
  3. 1, 2, and 3
  4. All, 1, 2, 3, 4

Answer: D) All, 1, 2, 3, 4

Explanation:

There are 4 types of datatypes in C++:

  1. Basic Datatype
  2. Derived Datatype
  3. Enumeration data type
  4. User Defined datatype

Discuss this Question


38. The size of basic datatypes can be changed according to 32 or 64-bit operating systems?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, it is true, the size of basic datatypes can be changed according to 32 or 64-bit operating systems.

Discuss this Question


39. If we use value "3.14" then what will be the data type of the given value?

  1. float
  2. double
  3. long double
  4. none of the above

Answer: B) double

Explanation:

If we use any floating-point value with the suffix "F" in C++ that will be double type.

Discuss this Question


40. Which of the following is the correct format specifier for long double-type values in C++?

  1. %f
  2. %ld
  3. %lf
  4. %ldf

Answer: C) %lf

Explanation:

The "%lf" format specifier is used for long double in C++.

Discuss this Question


41. What is the size of a long double in C++?

  1. 8 bytes
  2. 10 bytes
  3. 12 bytes
  4. 16 bytes

Answer: B) 10 bytes

Explanation:

The size of a long double in C++ is 10 bytes.

Discuss this Question


42. Is C++ language supports both signed and unsigned literals?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, C++ supports both signed and unsigned literals.

Discuss this Question


43. Which of the following is not the basic type in C++?

  1. int
  2. float
  3. array
  4. char

Answer: C) array

Explanation:

The "array" is a derived datatype in C++. It is not a fundamental datatype in C++.

Discuss this Question


44. Can we create a character variable that will occupy more than 1 byte in memory?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, in C++, using wchar_t we can declare a variable that will occupy more than 1 byte of memory space.

Discuss this Question


45. For which type, the format specifier "%i" is used?

  1. int
  2. float
  3. array
  4. char

Answer: A) int

Explanation:

We can use a "%d" or "%i" format specifier for integer variables in C++.

Discuss this Question


46. Which of the following is not a correct qualifier in C++?

  1. Size qualifier
  2. Type qualifier
  3. Sign qualifier
  4. None of the above

Answer: D) None of the above

Explanation:

There are 3 types of qualifiers used in C++:

  1. Size qualifier
  2. Sign qualifier
  3. Type qualifier

Discuss this Question


47. By default, "int" is?

  1. Signed integer
  2. Unsigned integer

Answer: A) Signed integer

Explanation:

In C++, "int" is a signed integer.

Discuss this Question


48. The data type "short" and "short int" are similar in C++?

  1. True
  2. False

Answer: A) True

Explanation:

"short" and "short int" are similar types in C++.

Discuss this Question


49. How many byte(s) does a short type take in C++?

  1. 1
  2. 2
  3. 3
  4. 4

Answer: B) 2

Explanation:

In C++, the short or short int takes 2 bytes (16 bits) in memory.

Discuss this Question


50. The operator '+' is?

  1. Unary Operator
  2. Binary Operator
  3. Both Unary and Binary
  4. None of the above

Answer: C) Both Unary and Binary

Explanation:

In C++, the operator '+' can be used as a binary and unary operator.

Discuss this Question


51. The operator '%' is known as?

  1. Division Operator
  2. Modulus Operator
  3. Percentage Operator
  4. None of the above

Answer: B) Modulus Operator

Explanation:

In C++, the operator '%' is known as the modulus operator, which is used to find the remainder.

Discuss this Question


52. Which of the following operator is a ternary operator?

  1. +=
  2. !=
  3. ::
  4. ?:

Answer: D) ?:

Explanation:

In C++, the operator '?:' is a ternary operator, it operates on 3 operands, it is also known as a conditional operator.

Discuss this Question


53. Which of the following operator is known as Scope Resolution Operator?

  1. ::
  2. ?:
  3. ->
  4. .

Answer: A) ::

Explanation:

In C++, the operator '::' is known as the Scope Resolution operator.

Discuss this Question


54. Which of the following operator is known as Referential Operator?

  1. !=
  2. ?:
  3. ->
  4. sizeof

Answer: C) ->

Explanation:

In C++, the operator '->' is known as the Referential operator.

Discuss this Question


55. The sizeof() is a?

  1. Unary Operator
  2. Binary Operator
  3. Ternary Operator
  4. None of the above

Answer: A) Unary Operator

Explanation:

In C++, the sizeof() is a unary operator.

Discuss this Question


56. The associativity of unary operators is?

  1. Left to Right
  2. Right to Left

Answer: B) Right to Left

Explanation:

In C++, the associativity of unary operators is Right to Left.

Discuss this Question


57. The associativity of the "[]" operator is?

  1. Left to Right
  2. Right to Left

Answer: A) Left to Right

Explanation:

In C++, the associativity of the "[]" operator is Left to Right.

Discuss this Question


58. The associativity of the conditional operator is?

  1. Left to Right
  2. Right to Left

Answer: B) Right to Left

Explanation:

In C++, the associativity of the conditional operator "?:" is Right to Left.

Discuss this Question


59. Which of the following operator is used to return the address of a variable?

  1. *
  2. ->
  3. &
  4. None of the above

Answer: C) &

Explanation:

In C++, the "&" operator is used to return the address of a variable.

Discuss this Question


60. Which of the following is known as the "value of" operator?

  1. *
  2. ->
  3. &
  4. None of the above

Answer: A) *

Explanation:

In C++, the "*" operator is known as the "value of" operator.

Discuss this Question


61. Which of the following is known as the "NOT" operator?

  1. ~
  2. !
  3. NOT
  4. None of the above

Answer: B) !

Explanation:

In C++, the "!" operator is known as the "NOT" operator.

Discuss this Question


62. Which of the following is not an arithmetic operator?

  1. %
  2. /
  3. !
  4. *

Answer: C) !

Explanation:

In C++, the "!" operator is not an arithmetic operator, it is a logical operator.

Discuss this Question


63. Which of the following statement is correct about the global variable?

  1. A variable defined inside the function or block is known as a global variable.
  2. A variable defined outside the function or block is known as a global variable.
  3. Global variables can only declare inside the “.h” file.

Answer: B) A variable defined outside the function or block is known as a global variable.

Explanation:

The 2nd statement is correct about the global variable.

Discuss this Question


64. The system automatically initializes a local variable?

  1. True
  2. False

Answer: B) False

Explanation:

The system automatically initializes a global variable whereas we need to initialize local variables explicitly.

Discuss this Question


65. The default value of a variable that is declared using register storage class?

  1. 0
  2. Garbage

Answer: B) Garbage

Explanation:

The default value of the variable, which is declared using the register storage class is garbage.

Discuss this Question


66. Which of the following is the default storage class in C++?

  1. auto
  2. extern
  3. register
  4. static

Answer: A) auto

Explanation:

The "auto" is the default storage class in C++.

Discuss this Question


67. The "mutable" is a storage class in C++?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, "mutable" is a storage class in C++.

Discuss this Question


68. Which of the following escape sequence is used to print double quotes on the console screen?

  1. %”
  2. /”
  3. *”
  4. None of the above

Answer: B) /”

Explanation:

The escape sequence /" prints double quotes on the console screen.

Discuss this Question


69. Which of the following escape sequence is used to print the percentage symbol on the console screen?

  1. %%
  2. /%
  3. *%
  4. None of the above

Answer: A) %%

Explanation:

The escape sequence %% is used to print the percentage symbol on the console screen.

Discuss this Question


70. Which of the following statement is correct about default arguments?

  1. Arguments that cannot be passed to the function
  2. Arguments with a default value that is not mandatory to be passed into the function
  3. Arguments that always take the same data value
  4. None of the above

Answer: B) Arguments with a default value that is not mandatory to be passed into the function

Explanation:

In C++, we can create functions with default arguments. The default arguments are used with a default value that is not mandatory to be passed into the function.

Discuss this Question


71. Which of the following condition is correct for the default arguments?

  1. Default arguments must be the last arguments in the function declaration.
  2. Default arguments must be the first argument in the function declaration.
  3. Default arguments can be declared anywhere in the function declaration.
  4. None of the above

Answer: A) Default arguments must be the last arguments in the function declaration.

Explanation:

In C++, we can create functions with default arguments. The default arguments must be the last argument in the function declaration.

Discuss this Question


72. Which of the following function can be called without any arguments?

  1. int print(int count, char ch='*')
  2. int print(char ch='*')
  3. int print(char ch='*',int count)
  4. int print(char ch)

Answer: B) int print(char ch='*')

Explanation:

In the above options, option B is correct.

Discuss this Question


73. Which of the following is the correct function prototype?

  1. void printchar(int cnt=0, char ch, int val=0)
  2. void printchar(int cnt=0, char='*')
  3. void printchar(int cnt, char ch='*')
  4. void printchar(char ch='c', int cnt)

Answer: C) void printchar(int cnt, char ch='*')

Explanation:

In the above options, option C is correct.

Discuss this Question


74. Which of the following function will be called with the independent syntax "sample(10,20,30);"?

  1. void sample(int x, int y)
  2. void sample(int x=0, int y, int z)
  3. float sample(int x=0, y=0, z=0)
  4. void sample(int x, int y, int z=0)

Answer: D) void sample(int x, int y, int z=0)

Explanation:

In the above options, option D is correct. Option C is incorrect because the return type is "float" and the syntax given is independent which means it doesn't return any value.

Discuss this Question


75. Which of the following is an incorrect call to the function void sample(int a, int b=0, int c=0)?

  1. sample(10,20,30);
  2. sample();
  3. sample(50);
  4. sample(30,40);

Answer: B) sample();

Explanation:

Here we need to pass at least one argument to the function.

Discuss this Question


76. Which of the following statement is correct about Default arguments?

  1. Default arguments are allowed in the argument list of the function declaration.
  2. Default arguments are allowed in the return type of the function declaration.
  3. Default arguments are allowed with the class name definition.
  4. Default arguments are allowed with floating-point type values.

Answer: A) Default arguments are allowed in the argument list of the function declaration.

Explanation:

Default arguments are allowed in the argument list of the function declaration.

Discuss this Question


77. Which of the following statement is not correct about Default arguments?

  1. Default arguments are allowed with pointer and reference to function declaration.
  2. Default arguments are not allowed with a declaration of a pointer to functions.
  3. Default arguments are not allowed with the reference to functions.
  4. None of the above

Answer: A) Default arguments are allowed with pointer and reference to function declaration.

Explanation:

Default arguments are not allowed with pointer and reference to function declaration.

Discuss this Question


78. The default argument gets bound during declaration but is executed during the function call?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, the default argument gets bound during declaration but is executed during the function call.

Discuss this Question


79. Can we implement a constructor with a default argument?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, we can implement a constructor with a default argument.

Discuss this Question


80. How many sequences of statements are available in C++?

  1. 6
  2. 5
  3. 4
  4. 3

Answer: B) 5

Explanation:

There are following sequence of statements is available in C++:

  1. Pre-processor directives
  2. Comments
  3. Declarations
  4. Function Declarations
  5. Executable statements

Discuss this Question


81. Which of the following is/are a decision making statement?

  1. IF statements
  2. Switch statement
  3. Conditional operators
  4. None of the above

Options:

  1. 1 and 2
  2. 1 and 3
  3. 4
  4. 1, 2, and 3

Answer: D) 1, 2, and 3

Explanation:

In C++, Decision-making statements are:

  • IF statements
  • Switch Statements
  • Conditional operators.

Discuss this Question


82. Which of the following statement can replace the if-else statement?

  1. while loop
  2. do-while loop
  3. for loop
  4. conditional operator

Answer: D) conditional operator

Explanation:

In C++, we can replace if-else statements using conditional operators.

Discuss this Question


83. Which of the following is the best option to make decisions for multiple choices?

  1. if
  2. if-else
  3. if-else-if
  4. All the above

Answer: C) if-else-if

Explanation:

In C++, "if-else-if" is the best option for multiple choices.

Discuss this Question


84. Can we use the string in the Switch statement for case selection?

  1. True
  2. False

Answer: B) False

Explanation:

In C++, we cannot use the string in Switch stamen for case selection.

Discuss this Question


85. Which of the following is an entry control loop?

  1. While Loop
  2. Do While loop

Answer: A) While Loop

Explanation:

While loop is an entry control loop, in a "while" loop we need to check the condition before executing the loop body.

Discuss this Question


86. Which of the following is an exit control loop?

  1. While Loop
  2. Do While loop
  3. For loop
  4. None of the above

Answer: B) Do While loop

Explanation:

The do-while loop is an entry control loop, in the "while" loop we need to check the condition before executing the loop body.

Discuss this Question


87. Which of the following loop is normally used for a menu-driven program?

  1. Do While loop
  2. For loop
  3. While loop
  4. None of the above

Answer: A) Do While loop

Explanation:

The do-while loop is used for a menu-driven program in C++.

Discuss this Question


88. Which of the following loop, in which we have to execute the body of the loop before checking the condition?

  1. Do While loop
  2. For loop
  3. While loop
  4. None of the above

Answer: A) Do While loop

Explanation:

In the Do-while loop, we have to execute the body of the loop before checking the condition.

Discuss this Question


89. Which of the following types of variables can be used in the Switch statement for case selection?

  1. int, float, char
  2. int, char
  3. int, double
  4. Any fundamental type

Answer: A) int, float, char

Explanation:

We can use only int, char type variables in the switch statement for case selection.

Discuss this Question


90. In switch statements, Expression in parenthesis "( )" after the switch statement is mandatory?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, the Expression in parenthesis "()" after the switch statement is mandatory.

Discuss this Question


91. Which of the following statement is correct about the "break" statement?

  1. The break statement cancels the remaining iterations
  2. Break statement skips a particular iteration
  3. The break statement terminates the program
  4. None of the above

Answer: A) The break statement cancels the remaining iterations

Explanation:

The Break statement cancels the remaining iterations.

Discuss this Question


92. Which of the following loop is faster in C++?

  1. Do While loop
  2. For loop
  3. While loop
  4. All loops work at the same speed

Answer: D) All loops work at the same speed

Explanation:

All loops work at the same speed.

Discuss this Question


93. Which of the following statement is used to quit the loop immediately?

  1. continue
  2. break
  3. while
  4. None of the above

Answer: B) break

Explanation:

The break statement is used to quit the loop immediately.

Discuss this Question


94. Which of the following statement is also known as a "switch" statement?

  1. selective statement
  2. choose statement
  3. bitwise statement
  4. certain statement

Answer: A) selective statement

Explanation:

The switch statement is also known as the selective statement.

Discuss this Question


95. Which of the following statement is also known as a "continue" statement?

  1. goto statement
  2. bitwise statement
  3. skipping statement
  4. certain statement

Answer: C) skipping statement

Explanation:

The "continue" statement is also known as the skipping statement.

Discuss this Question


96. Which of the following is the correct syntax of the "for" loop?

  1. for(condition; increment; declaration){ //body of the loop };
  2. for(declaration; increment/decrement; condition){ //body of the loop };
  3. for(initalization; condition; increment/decrement){ //body of the loop };
  4. None of the above

Answer: C) for(initalization; condition; increment/decrement){ //body of the loop };

Explanation:

The 3rd option is correct.

Discuss this Question


97. Which of the following is the correct syntax of the "do-while" loop?

  1. do{ //Body of the loop }while(condition);
  2. dowhile(condition){ //Body of the loop };
  3. do while(condition){ //Body of the loop };
  4. do{ //Body of the loop }while(condition)

Answer: A) do{ //Body of the loop }while(condition);

Explanation:

The 1st option is correct.

Discuss this Question


98. Which of the symbol is used with the label in the "goto" statement?

  1. @
  2. :
  3. #
  4. !

Answer: B) :

Explanation:

The colon ":" symbol is used with the label in the "goto" statement.

Discuss this Question


99. Which of the following loop is the best option when the number of iterations is known?

  1. While loop
  2. For loop
  3. Do while loop
  4. all loops require that the iterations be known

Answer: B) For loop

Explanation:

The "for" loop is the best option when the number of iterations is known.

Discuss this Question


100. Execution of C++ program starts from?

  1. void function
  2. class
  3. main function
  4. user-defined function

Answer: C) main function

Explanation:

Execution of the C++ program starts from the main () function.

Discuss this Question


101. Which of the following given option is used to complete the function declaration?

  1. Semicolon
  2. Colon
  3. Comma
  4. None of the above

Answer: C) Comma

Explanation:

The semicolon is used to complete the function declaration.

Discuss this Question


102. How many arguments can be passed to a function?

  1. 128
  2. 256
  3. 512
  4. Vary from compiler to compiler

Answer: D) Vary from compiler to compiler

Explanation:

It varies from compiler to compiler and also different C99 and C++ standards.

Discuss this Question


103. Which of the following are the mandatory part of the function prototype?

  1. Function name and argument list
  2. Function name and return type
  3. Function name, argument list, and return type
  4. Return type and argument list

Answer: B) Function name and return type

Explanation:

The function name and return type are the mandatory part of the function prototype.

Discuss this Question


104. What will be the output of the following program?

#include <iostream>
using namespace std;

void sayHello();
{
    cout << "Hello World";
}

int main()
{
    sayHello();
    return 0;
}

Options:

  1. Hello World
  2. Hello
  3. Error
  4. None of the above

Answer: B) CSS

Explanation:

The above program will generate a syntax error because we use a semicolon in the definition of the sayHello() function. The correct program is given below:

#include <iostream>
using namespace std;

void sayHello()
{
    cout << "Hello World";
}

int main()
{
    sayHello();
    return 0;
}

Discuss this Question


105. Can we use the return type void in the main() function in a C++ program?

  1. Yes
  2. No

Answer: B) NO

Explanation:

No, we cannot use the return type void in the main () function, we have to use the return type "int" with the main() function.

Discuss this Question


106. Which of the following is a more effective way to call a function with arguments?

  1. Call by value
  2. Call by reference
  3. Call by address
  4. None of the above

Answer: B) Call by reference

Explanation:

The "call by reference" is a more effective way to call a function with arguments because it reduces the overall time and memory use.

Discuss this Question


107. How many minimum numbers of functions are required to execute a C++ program?

  1. 1
  2. 2
  3. 3
  4. 4

Answer: A) 1

Explanation:

To execute a C++ program, we required only 1 function which is the main() function. Because the main() function is the entry point for the program.

Discuss this Question


108. What is the lifetime of a static variable declared in a user-defined function?

  1. Within the function only
  2. Within the main function only
  3. Whole program
  4. None of the above

Answer: C) Whole program

Explanation:

The lifetime of a static variable is in the whole program. But its scope is within the function only.

Discuss this Question


109. Which of the following statement is correct about inline function?

  1. A function that is substituted at the place of call.
  2. A function that is called at compile time
  3. A function that contains only looping statements
  4. None of the above

Answer: A) A function that is substituted at the place of call.

Explanation:

A function that is substituted at the place of call is called an inline function.

Discuss this Question


110. A function that is defined inside a class without any complex statement will be inline.

  1. True
  2. False

Answer: A) True

Explanation:

Yes, A function that is defined inside a class without any complex statement will be inline.

Discuss this Question


111. An inline function is substituted at the place of function call during?

  1. Compile Time
  2. Runtime

Answer: A) Compile Time

Explanation:

An inline function is substituted at the place of the function call during compile time.

Discuss this Question


112. A recursive function can be inline?

  1. Yes
  2. No

Answer: B) NO

Explanation:

A recursive function can never be inline in C++.

Discuss this Question


113. An inline function can contain static variables?

  1. Yes
  2. No

Answer: B) NO

Explanation:

An inline function cannot contain static variables.

Discuss this Question


114. An inline function is faster than a normal function?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, an inline function is faster than a normal function because it does not require a context switch from function call to function definition.

Discuss this Question


115. Default values for a function are defined.

  1. In function declaration
  2. In function definition
  3. During function call
  4. None of the above

Answer: A) In function declaration

Explanation:

We can define default values for a function in the function declaration.

Discuss this Question


116. Can we define the inline function outside the class in C++ program?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can define an inline function inside or outside the class.

Discuss this Question


117. Can we access the elements of an array outside the bound?

  1. Yes
  2. No

Answer: B) NO

Explanation:

No, we cannot access the elements of an array outside the bound in C++. It can generate logical and runtime errors.

Discuss this Question


118. Index of an array starts from?

  1. 1
  2. 2
  3. 0
  4. -1

Answer: C) 0

Explanation:

The index of an array starts from 0 in C++.

Discuss this Question


119. In C++, the Array name denotes?

  1. The base address of the array
  2. The first value of the array
  3. Last value of the array
  4. None of the above

Answer: A) The base address of the array

Explanation:

Array name denotes the base address of the array.

Discuss this Question


120. If we create an array "Arr", which is the correct way to access the first element of the array?

  1. Arr[0]
  2. 0[Arr]
  3. *(Arr+0)
  4. All the above

Answer: D) All the above

Explanation:

All the given options are the correct way to access the first element of the array.

Discuss this Question


121. Can we create an array of objects in C++?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can create an array of objects in C++.

Discuss this Question


122. Can we create the 4-dimensional array in C++?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can create a 4-dimensional array using the below statement.
int arr[2][2][2][2];

Discuss this Question


123. An array occupies memory space in?

  1. Contiguous manner
  2. Fragmented manner
  3. Linked List
  4. None

Answer: A) Contiguous manner

Explanation:

In C++, an array occupies memory space in a contiguous manner.

Discuss this Question


124. How many dimensions are an array in C++?

  1. 1D array
  2. 2D Array
  3. 3D array
  4. No Limit

Answer: D) No Limit

Explanation:

There is no limit of dimensions for arrays in C++.

Discuss this Question


125. When we pass an array to the function, then the function call will be?

  1. Call by value
  2. Call by reference
  3. Both A and B
  4. None of these

Answer: B) Call by reference

Explanation:

When we pass an array to the function then the function call will be "call by reference".

Discuss this Question


126. Which of the following statement is correct about the is_array() function in C++??

  1. The is_array() function is used to check whether a variable is an array or not.
  2. The is_array() function is used to check whether a variable is a 1D array or not.
  3. The is_array() function is used to check whether a variable is a 1D or 2D array.
  4. None of these

Answer: A) The is_array() function is used to check whether a variable is an array or not.

Explanation:

The is_array() function is used to check whether a variable is an array or not.

Discuss this Question


127. Which of the following statement is correct about the is_same() function in C++?

  1. The is_same() function is used to check whether a variable is an array or not.
  2. The is_same() function is used to check if two variables of array type.
  3. The is_same() function is used to check if two variables have the same characteristics.
  4. None of these

Answer: C) The is_same() function is used to check if two variables have the same characteristics.

Explanation:

The is_same() function is used to check if two variables have the same characteristics.

Discuss this Question


128. Which of the following function is used to get the dimensions of the given array?

  1. getdimension
  2. getarraydimension
  3. rank
  4. arrayrank

Answer: C) rank

Explanation:

The rank function is used to get the dimensions of the given array.

Discuss this Question


129. Which of the following function is used to remove all dimensions from an array?

  1. remove_dimension
  2. remove_all_dimensions
  3. remove_extent
  4. remove_all_extents

Answer: D) remove_all_extents

Explanation:

The remove_all_extents is used to remove all dimensions from an array.

Discuss this Question


130. Which of the following contains an array type manipulation function?

  1. std namespace
  2. <iostream>
  3. <array>
  4. None of the above

Answer: A) std namespace

Explanation:

The "std" namespace contains an array type manipulation function.

Discuss this Question


131. Is it true, when array initialization is part of the definition then the size of the array is not required?

  1. True
  2. False

Answer: A) True

Explanation:

Yes, the size of the array is not required when we initialize an array as part of the definition.

Discuss this Question


132. Which of the following operator is known as the indirection operator?

  1. ->
  2. &
  3. *
  4. None of the above

Answer: C) *

Explanation:

The "*" operator is known as the indirection operator in C++.

Discuss this Question


133. Which of the following operator is known as a referential operator?

  1. ->
  2. &
  3. *
  4. None of the above

Answer: A) ->

Explanation:

The "->" operator is known as a referential operator in C++.

Discuss this Question


134. Which of the following is invalid?

  1. string str, *ptr=0;
  2. int a, float *f = &a;
  3. int *ptr;
  4. None of the above

Answer: B) int a, float *f = &a;

Explanation:

The 2nd option is invalid because we are trying to initialize the address of the integer variable to a float pointer.

Discuss this Question


135. Can we point to a datatype using a pointer?

  1. True
  2. False

Answer: B) False

Explanation:

No, we cannot point to a datatype using a pointer.

Discuss this Question


136. Which of the following is the incorrect way to declare a pointer?

  1. int *ptr;
  2. int* ptr;
  3. int &ptr;
  4. int *ptr=0;

Answer: C) int &ptr;

Explanation:

The 3rd option is the incorrect way to declare a pointer.

Discuss this Question


137. A pointer can be initialized with?

  1. Address of variable of the same type
  2. NULL
  3. 0
  4. All the above

Answer: D) All the above

Explanation:

A pointer can be initialized with the address of a variable of the same type, NULL, and zero.

Discuss this Question


138. Which of the following is the correct way to get value from pointer "ptr"?

  1. ptr
  2. &ptr
  3. *ptr
  4. All the above

Answer: C) *ptr

Explanation:

The "*ptr" is the correct way to get the value from the pointer ptr.

Discuss this Question


139. What is the size of a pointer?

  1. 4 bytes
  2. 8 bytes
  3. 16 bytes
  4. Vary from processor to processor

Answer: D) Vary from processor to processor

Explanation:

The size of the pointer is varied from processor to processors like 16-bit, 32-bit, and 64-bit processors.

Discuss this Question


140. Which of the following is the correct option?
int* a, b;

  1. a is a pointer to an integer and b is an integer variable
  2. b is a pointer to an integer and a is an integer variable
  3. both a and b are pointers.

Answer: A) a is a pointer to an integer and b is an integer variable

Explanation:

In the above-given statement, a is a pointer to an integer and b is an integer variable.

Discuss this Question


141. Can we create a pointer to point a file in C++?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can create a pointer to point a file in c++ using the "FILE*" type.

Discuss this Question


142. What will be the output of the following program?

#include <iostream>
using namespace std;

int main()
{
    int x = 50, y = 20;
    int *p1 = &x, *p2 = &y;
    p1 = p2;

    cout << *p1;

    return 0;
}

Options:

  1. 50
  2. 20
  3. Address
  4. Error

Answer: B) Address

Explanation:

Here, initially, pointer p1 points to variable x, and pointer p2 points to y variable. Then pointer p2 is assigned to pointer p1. So when we print *p2 then it will print the value of variable "y" which is 20.

Discuss this Question


143. A wild pointer is also known as a dangling pointer?

  1. Yes
  2. No

Answer: B) No

Explanation:

An uninitialized pointer is known as a wild pointer while a dangling pointer points to a location that has been deleted.

Discuss this Question


144. Which of the following can point to any type of variable?

  1. Far pointer
  2. Null pointer
  3. Void pointer
  4. Dangling pointer

Answer: C) Void pointer

Explanation:

A void pointer can point to any type of variable, to access value from a void pointer we need to typecast it.

Discuss this Question


145. What is the size of a far pointer?

  1. 16-bit
  2. 32-bit
  3. 64-bit
  4. None of the above

Answer: B) 32-bit

Explanation:

The size of a far pointer is 32-bit.

Discuss this Question


146. Can we access memory outside the current segment using a far pointer?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can access memory outside the current segment using a far pointer.

Discuss this Question


147. Which of the following is the incorrect type of pointer in C++?

  1. Near
  2. Far
  3. Huge
  4. Small

Answer: D) Small

Explanation:

The small pointer is the incorrect type of pointer in C++.

Discuss this Question


148. In Smart pointer, we did not require to take care to deallocate memory space?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, In smart pointers we did not require to take care to deallocate memory space, allocated memory will be free automatically.

Discuss this Question


149. Which of the following is not the correct type of smart pointer?

  1. unique_ptr
  2. shared_ptr
  3. week_ptr
  4. far_ptr

Answer: D) far_ptr

Explanation:

The "far_ptr" is not the correct type of smart pointer in C++.

Discuss this Question


150. Is the "unique_ptr" smart pointer maintaining a reference counter?

  1. Yes
  2. No

Answer: B) NO

Explanation:

The "unique_ptr" does not maintain a reference counter while "shared_ptr" maintains a reference counter.

Discuss this Question


151. Which of the following function is used to maintain a reference counter with a smart pointer?

  1. use_count()
  2. count()
  3. ptr_count()
  4. shared_count()

Answer: A) use_count()

Explanation:

The use_count() function is used to maintain a reference counter with a "shared_ptr" smart pointer.

Discuss this Question


152. Which type of memory is allocated using dynamic memory allocation?

  1. Stack
  2. Heap
  3. Static
  4. Program code

Answer: B) Heap

Explanation:

When we use dynamic memory allocation, memory is allocated in the heap segment.

Discuss this Question


153. Which of the following is/are used for dynamic memory allocation?

  1. malloc
  2. calloc
  3. new
  4. free

Options:

  1. 1 and 2
  2. 1, 2, and 4
  3. 2 and 3
  4. All 1,2,3, and 4

Answer: D) All 1,2,3, and 4

Explanation:

All the given function names and operators are used for dynamic memory allocation in C++.

Discuss this Question


154. Can we allocate memory for an object dynamically?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can allocate memory for an object using "new" and malloc() in C++.

Discuss this Question


155. Is it not required to deallocate the dynamically allocated memory manually in the program?

  1. Yes
  2. No

Answer: B) No

Explanation:

We need to manually deallocate the dynamically allocated memory using free() and delete operator in our program.

Discuss this Question


156. Which of the following operator is used to release dynamically allocated memory space?

  1. new
  2. remove
  3. release
  4. delete

Answer: D) delete

Explanation:

The "delete" operator is used to release dynamically allocated memory space.

Discuss this Question


157. The "new" is a function in C++?

  1. Yes
  2. No

Answer: B) No

Explanation:

No, "new" is an operator in C++, which is used to allocate memory space dynamically.

Discuss this Question


158. When we allocate memory space for an object using "new", will it call a constructor?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, when we allocate memory space for an object using the "new" operator, it will call the constructor. But when we allocate memory space for an object using the "malloc ()" function, it will not call the constructor.

Discuss this Question


159. On failure, the "new" operator returns?

  1. NULL
  2. -1
  3. bad_alloc exception
  4. None of these

Answer: C) bad_alloc exception

Explanation:

On failure, the "new" operator returns a "bad_alloc" exception.

Discuss this Question


160. The "delete" is an operator in C++?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, "delete" is an operator in C++, which is used to deallocate memory space dynamically.

Discuss this Question


161. During the deallocation of dynamically allocated memory for an object using the "free()" function destructor gets called?

  1. Yes
  2. No

Answer: B) No

Explanation:

No, the "free()" function does not call the destructor while the "delete" operator call destructor during the deallocation of dynamically allocated memory for an object.

Discuss this Question


162 . Which of the following is a valid way to allocate dynamic memory for an integer variable?

  1. int *ptr = new int(111);
  2. int *ptr = NULL;ptr = new int; *ptr=111;
  3. int *ptr;ptr = new int; *ptr=111;
  4. All the above

Answer: D) All the above

Explanation:

All the given options are valid to allocate dynamic memory for an integer variable.

Discuss this Question


163. Which of the following is correct?

  1. "ptr = calloc(a, b)" is equivalent to ptr = malloc(a * b); memset(ptr, 0, a * b);
  2. "ptr = calloc(a, b)" is equivalent to ptr = malloc(a * b);
  3. "ptr = calloc(a, b)" is equivalent to ptr = malloc(a); memset(ptr, 0, a);
  4. "ptr = calloc(a, b)" is equivalent to ptr = malloc(a); memset(ptr, 0, a);

Answer: A) "ptr = calloc(a, b)" is equivalent to ptr = malloc(a * b); memset(ptr, 0, a * b);

Explanation:

Option A is correct.

Discuss this Question


164. What problem may occur with the below code?

#include <stdio.h>
int main()
{
    float* ptr = (int*)malloc(sizeof(float));
    ptr = NULL;
    free(ptr);
}

Options:

  1. Memory leak
  2. Dangling pointer
  3. Compiler error
  4. None of the above

Answer: A) Memory leak

Explanation:

The above program will create a memory leak because we assigned the NULL to the pointer and free the pointer.

Discuss this Question


165. Which programming language required heap memory allocation in the run time environment?

  1. A language that uses global variables
  2. A language that supports dynamic scoping
  3. A language that allows dynamic data structures
  4. A language that supports recursion

Answer: C) A language that allows dynamic data structures

Explanation:

A language that allows dynamic data structures required heap memory allocation in the run time environment.

Discuss this Question


166. Which of the following statement is correct about class in C++?

  1. Class is an instance that contains data member and member functions.
  2. Class is fundamental that contains data member and member functions.
  3. Class is a blueprint for a data type that encapsulates data member and member functions.
  4. None of the above

Answer: C) Class is a blueprint for a data type that encapsulates data member and member functions.

Explanation:

Class is a blueprint for a data type that encapsulates data member and member functions.

Discuss this Question


167. Which of the following symbol is used at the end of the class definition?

  1. Colon.
  2. Semicolon.
  3. Scope Resolution operator.
  4. None of the above

Answer: B) Semicolon.

Explanation:

The semicolon ( ; ) symbol is used at the end of the class definition.

Discuss this Question


168. Can we define member functions outside the class?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can define member functions inside or outside the class.

Discuss this Question


169. Which of the following symbol is used to define member functions outside the class?

  1. Colon.
  2. Semicolon.
  3. Scope Resolution operator.
  4. None of the above

Answer: C) Scope Resolution operator.

Explanation:

The scope resolution operator ( :: ) symbol is used to define member functions outside the class.

Discuss this Question


170. By default, members of a class are:

  1. Public
  2. Private
  3. Protected
  4. None of the above

Answer: B) Private

Explanation:

By default, members of a class are private in C++.

Discuss this Question


171. Can we define a constructor inside the structure?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, just like class, we can define a constructor inside the structure in C++.

Discuss this Question


172. By default, members of a structure are:

  1. Public
  2. Private
  3. Protected
  4. None of the above

Answer: A) Public

Explanation:

By default, members of a structure are public in C++.

Discuss this Question


173. Can we define a destructor inside the structure?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, just like class, we can define a destructor inside the structure in C++.

Discuss this Question


174. What is the size of an empty class in C++?

  1. 1 Byte
  2. 0 Byte
  3. 2 Byte
  4. 4 Byte

Answer: A) 1 Byte

Explanation:

The size of an empty class is 1 byte, every object occupies at least one byte to differentiate memory address space for objects.

Discuss this Question


175. Can we create multiple objects of a class in C++?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can create multiple objects of the class in C++.

Discuss this Question


176. Which of the following operator is used to access the members using the object of a class?

  1. .
  2. ->
  3. :
  4. None of the above

Answer: A) .

Explanation:

The membership operator (.) is used to access the members using the object of a class in C++.

Discuss this Question


177. Which of the following operator is used to access the members using the pointer to the object of a class?

  1. .
  2. ->
  3. :
  4. None of the above

Answer: B) ->

Explanation:

The referential operator -> is used to access the members using the pointer to the object of a class in C++.

Discuss this Question


178. Is it true, Objects of a class do not share non-static members?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, objects of a class do not share non-static members. Every object has its own copy.

Discuss this Question


179. Can we create a "const" object in C++?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can create a "const" object in C++, using a "const" object. Any attempt to change the data member of const objects results in a compile-time error.

Discuss this Question


180. Can we create "const" member functions in class?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can create "const" member functions in the class. In the "const" member function, we cannot change the value of data members.

Discuss this Question


181. Can we pass a class into a function as an argument in C++?

  1. Yes
  2. No

Answer: B) No

Explanation:

No, we cannot pass a class into a function as an argument, we can pass an object of a class as an argument to the function in C++.

Discuss this Question


182. How many types of specifiers can be used in class in C++?

  1. 1
  2. 2
  3. 3
  4. 4

Answer: C) 3

Explanation:

There are 3 types of specifiers used in class are given below:

  1. Public
  2. Private
  3. Protected

Discuss this Question


183. Which of the following is/are the correct type of class?

  1. Abstract class
  2. Concrete class
  3. Both A and B
  4. None of the above

Answer: C) Both A and B

Explanation:

Abstract and concrete are the correct types of classes.

Discuss this Question


184. Can we create objects of a class with the definition of class?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can create objects of class at the end of the class definition before the semicolon. For example.

	
class Sample {
int a, b;
}
obj1, obj2;

Discuss this Question


185. Which of the following statement is correct about constructors in C++?

  1. A constructor is used to destroy an object.
  2. Constructor is used to initializing data members when an object gets created.
  3. Constructor is used to call the private function from outside the class.
  4. None of the above

Answer: B) Constructor is used to initializing data members when an object gets created.

Explanation:

Constructor is a special type of member function that automatically calls when an object gets created. It is used to initialize the data members of the class.

Discuss this Question


186. How many parameters can be accepted by a default constructor?

  1. 1
  2. 2
  3. 0
  4. Infinite

Answer: C) 0

Explanation:

A default constructor accepts 0 parameters.

Discuss this Question


187. What is the return type of a constructor?

  1. void
  2. int
  3. float
  4. None of the above

Answer: D) None of the above

Explanation:

A constructor does not have any return type.

Discuss this Question


188. Which of the following is an incorrect type of constructor in C++?

  1. Copy constructor
  2. Move constructor
  3. Default constructor
  4. Parameterized constructor

Answer: B) Move constructor

Explanation:

There is no "move constructor" in C++.

Discuss this Question


189. If we did not create any constructor in the class, then which of the following constructor is automatically added to the class?

  1. Copy constructor
  2. Default constructor
  3. Parameterized constructor
  4. None of the above

Answer: B) Default constructor

Explanation:

If we did not create any constructor in the class, then the default constructor is automatically added to the class.

Discuss this Question


190. Can we overload the constructor in a class?

  1. Yes
  2. No

Answer: B) No

Explanation:

Yes, we can create multiple constructors in a class by overloading the constructor.

Discuss this Question


191. A constructor can be inline in C++?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, the constructor can be inline, as we know, inline is a request, not a command.

Discuss this Question


192. A default constructor is also known as a?

  1. Parameterized constructor
  2. Copy constructor
  3. No argument constructor

Answer: C) No argument constructor

Explanation:

A default constructor is also known as a no-argument constructor.

Discuss this Question


193. What will happen, when we create a class with a parameterized constructor and without having a zero-argument constructor, then we create an object of the class that needs a zero argument constructor?

  1. Linker error
  2. Compilation error
  3. Logical error
  4. None of the above

Answer: B) Compilation error

Explanation:

It will generate a compilation error.

Discuss this Question


194. When we create an object of class using the malloc() function then the constructor gets called?

  1. True
  2. False

Answer: B) False

Explanation:

No, when we create an object of class using the malloc() function then the constructor will not call, the constructor gets called when we use the "new" operator for object creation.

Discuss this Question


195. Constructor and Destructor have the same name but destructor is preceded by?

  1. ~
  2. !
  3. $
  4. #

Answer: A) ~

Explanation:

Constructor and Destructor have the same name but destructor is preceded by a tilde (~) symbol.

Discuss this Question


196. Can we create multiple destructors in class?

  1. Yes
  2. No

Answer: B) No

Explanation:

No, we cannot create multiple destructors in a C++ class.

Discuss this Question


197. Can we create a virtual constructor in a class?

  1. Yes
  2. No

Answer: B) No

Explanation:

No, we cannot create a virtual constructor in a class. Other than inline, no other keyword is allowed in the declaration of the constructor.

Discuss this Question


198. Can we create a virtual destructor in a class?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can create a virtual destructor in the C++ class.

Discuss this Question


199. Which of the following constructor is used to create an object by initializing data members using an existing object?

  1. Default constructor
  2. Dynamic constructor
  3. Copy constructor
  4. None of the above

Answer: C) Copy constructor

Explanation:

Copy constructor is used to create an object by initialize data members using existing object.

Discuss this Question


200. Can we implement copy constructor without passing reference of an object into it?

  1. Yes
  2. No

Answer: B) No

Explanation:

No, we cannot implement copy constructor without passing a reference of an object into it.

Discuss this Question


201. Which of the following is used to initialize the const members of the class using a constructor?

  1. Const constructor
  2. Default constructor
  3. Member initializer list
  4. Copy constructor

Answer: C) Member initializer list

Explanation:

In C++, a member initializer list is used to initialize the const members of the class.

Discuss this Question


202. Which of the following is responsible to create a default constructor in the class when the programmer does not create a constructor inside the class?

  1. Compiler
  2. Linker
  3. Loader
  4. Pre-processor

Answer: C) Loader

Explanation:

In C++, the Compiler is responsible to create a default constructor in the class when the programmer does not create a constructor inside the class.

Discuss this Question


203. When does a destructor gets called?

  1. When an object gets created
  2. When an object gets destroyed
  3. After calling constructor
  4. None of the above

Answer: B) When an object gets destroyed

Explanation:

A destructor gets called when an object is getting destroyed.

Discuss this Question


204. When we deallocate space for an object of class using the free() function then a destructor gets called?

  1. True
  2. False

Answer: B) False

Explanation:

No, when we deallocate space for an object of class using the free () function then a destructor will not call, the destructor gets called when we use the "delete" operator for object destruction.

Discuss this Question


References: C++ | Wikipedia



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.