0% found this document useful (0 votes)
41 views63 pages

List of C++ Multiple-Choice Questions and Answers

The document provides a comprehensive overview of the C++ programming language, covering its history, features, and key concepts. It includes questions and answers about the language's development, syntax, data types, operators, and object-oriented programming principles. Additionally, it addresses common misconceptions and technical details relevant to C++ programming.

Uploaded by

Gudeta Amsalu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views63 pages

List of C++ Multiple-Choice Questions and Answers

The document provides a comprehensive overview of the C++ programming language, covering its history, features, and key concepts. It includes questions and answers about the language's development, syntax, data types, operators, and object-oriented programming principles. Additionally, it addresses common misconceptions and technical details relevant to C++ programming.

Uploaded by

Gudeta Amsalu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

1. C++ language was developed by ___.

A. Dennis Rechard
B. Dennis M. Ritchie

C. Bjarne Stroustrup

D. Anders Hejlsberg

Answer: C) Bjarne Stroustrup


Explanation: C++ programming language was developed by Bjarne Stroustrup at Bell
Laboratories (formerly AT&T Bell Laboratories).
2. In which year, the name of the language was changed from "C with Classes" to C++?

A. 1979

B. 1972

C. 1983
D. 1986

Answer: C) 1983

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

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


A. B

B. C

C. Java
D. VB
Answer: B) C

Explanation: C++ is a successor of C language.

1
4. C++ language is a ___.

A. Object Oriented Language


B. Procedural Oriented Language

C. Structural Oriented Language

D. None of the above

Answer: A) Object Oriented Language


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

5. C++ follows ___.

A. Top-Down Design approach

B. Bottom-Up Design approach


C. Both of the above

D. None of the above.

Answer: B) Bottom-Up Design approach


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

6. C++ is a ___.

A. High-level language

B. Medium level language


C. Low-level language

D. 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).

2
7. How many keywords are in C++?

A. 32
B. 48

C. 99

D. 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.
8. Which of the following is not a valid keyword in C++ language?

A. while

B. for

C. switch
D. do-while

Answer: D) do-while

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

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


A. Identifiers are the combination of alphanumeric characters that can be used for function
and variable names.
B. Identifiers are a combination of alphanumeric characters that can be used for looping
statements.

C. Both of the above


D. 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++.

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

A. //
B. \\

C. /* */

D. ##

Answer: A) //
Explanation: We use "//" for single-line comments in C++.

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

A. //

B. \\
C. /* */

D. ##

Answer: C) /* */
Explanation: We use "/* */" for multi-line comment in C++.

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

A. True

B. False
Answer: A) True

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

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

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

A. 2014
B. 2015

C. 2017

D. 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

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

A. Assembler

B. Interpreter
C. Compiler

D. Both Interpreter and Compiler

Answer: C) Compiler

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

5
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:
A. 1 and 2

B. 3 and 4

C. 1, 3, 4

D. 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

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

A. .cpp

B. .c++
C. Both

D. None

Answer: c) Both
Explanation: We can use both ".cpp" and ".c++" for a C++ source code file.

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

A. GCC
B. c++

C. g++

D. None

Answer: C) g++
Explanation: The g++ command is used to compile C++ source files.

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

A. True

B. 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.

19. C++ supports automatic garbage collection?

A. True

B. 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.

20. C++ is case sensitive language?

A. True

B. False
Answer: A) True

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

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

1. Inheritance
2. Encapsulation

3. Abstraction

4. Polymorphism

Opation:
A. 1 and 2

B. 1, 2, and 3

C. 1, 2, and 4

D. 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
22. OOPs stands for?

A. Object Oriented Process System

B. Object Oriented Programming System

C. Object Oriented Programming Service


D. Object Orientation Programming System

Answer: B) Object Oriented Programming System

Explanation: OOPs stands for Object Oriented Programming System.

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

A. True
B. False

Answer: A) True

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

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

A. True
B. 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.

25. Stream is ___.

A. Group of non-printable character

B. Sequence of bytes
C. Set of errors

D. 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.

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

A. Input Operation
B. Output Operation

C. Both of above

D. 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.
9
27. Which of the following header file is used to define cin, cout?

A. <iomanip.h>
B. <iostream.h>

C. <fstream.h>

D. None of the above

Answer: B) <iostream.h>
Explanation: The <iostream.h> header file is used to define cin and cout.

28. The cin, cout are ___.

A. Library functions

B. structures
C. Pointers

D. 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.

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


A. cin

B. cout

C. cput
D. cerr
Answer: C) cput

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

10
30. The stdout stands for ___.

A. State Output
B. Standard Output

C. Stand Output

D. Stream Output

Answer: B) Standard Output


Explanation: The "stdout" stands for standard output. It is used to represent standard output
devices like the monitor.
31. Is it true, the cerr is an object of the ostream class?

A. True

B. 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.

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


A. <<

B. >>

C. ->
D. <<<

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.

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

A. >>>
B. >>

C. ->

D. <<<

Answer: B) >>
Explanation: In C++, ">>" is known as an extraction operator which is used with the "cin"
object to read user input.
34. The endl is a ___.

A. Macro

B. object

C. Pointers
D. function

Answer: A) Macro

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

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

A. cin
B. cout

C. cerr

D. endl

Answer: D) endl
Explanation: The "endl" object is used to print the newline as well as flush the stream.

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

A. ost
B. std

C. endl

D. none of the above

Answer: B) std
Explanation: The "std" namespace contains cin, and cout objects.

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:
A. 1 and 2

B. 1, 2, and 4

C. 1, 2, and 3

D. 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

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

A. True
B. 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.

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

A. float
B. double

C. long double

D. 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.

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

A. %f
B. %ld

C. %lf

D. %ldf

Answer: C) %lf
Explanation: The "%lf" format specifier is used for long double in C++.

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

A. 8 bytes
B. 10 bytes

C. 12 bytes

D. 16 bytes

Answer: B) 10 bytes

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

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


A. True

B. False

Answer: A) True

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


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

A. int

B. float

C. array
D. char

Answer: C) array

Explanation: The "array" is a derived datatype in C++. It is not a fundamental datatype in C++.
44. Can we create a character variable that will occupy more than 1 byte in memory?

A. True

B. 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.
45. For which type, the format specifier "%i" is used?
A. int

B. float

C. array
D. char

Answer: A) int

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

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

A. Size qualifier
B. Type qualifier

C. Sign qualifier

D. 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
47. By default, "int" is?

A. Signed integer

B. Unsigned integer
Answer: A) Signed integer

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

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

A. True
B. False

Answer: A) True

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

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


A. 1

B. 2

C. 3
D. 4

Answer: B) 2

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

16
50. The operator '+' is?

A. Unary Operator
B. Binary Operator

C. Both Unary and Binary

D. None of the above

Answer: C) Both Unary and Binary


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

51. The operator '%' is known as?

A. Division Operator

B. Modulus Operator
C. Percentage Operator

D. 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.

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


A. +=

B. !=

C. ::
D. ?:
Answer: D) ?:

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

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

A. ::
B. ?:

C. ->

D. .

Answer: A) ::
Explanation: In C++, the operator '::' is known as the Scope Resolution operator.

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

A. !=

B. ?:
C. ->

D. sizeof

Answer: C) ->
Explanation: In C++, the operator '->' is known as the Referential operator.

55. The sizeof() is a?

A. Unary Operator

B. Binary Operator
C. Ternary Operator

D. None of the above

Answer: A) Unary Operator

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


56. The associativity of unary operators is?

A. Left to Right

B. Right to Left
Answer: B) Right to Left

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

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

A. Left to Right
B. Right to Left

Answer: A) Left to Right

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

58. The associativity of the conditional operator is?


A. Left to Right

B. Right to Left

Answer: B) Right to Left

Explanation: In C++, the associativity of the conditional operator "?:" is Right to Left.
59. Which of the following operator is used to return the address of a variable?

A. *

B. ->
C. &

D. None of the above

Answer: C) &

Explanation: In C++, the "&" operator is used to return the address of a variable.
60. Which of the following is known as the "value of" operator?

A. *

B. ->

C. &
D. None of the above

Answer: A) *

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

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

A. ~
B. !

C. NOT

D. None of the above

Answer: B) !
Explanation: In C++, the "!" operator is known as the "NOT" operator.

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

A. %

B. /
C. !

D. *

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

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

A. A variable defined inside the function or block is known as a global variable.

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


C. 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.

64. The system automatically initializes a local variable?


A. True

B. False

Answer: B) False
Explanation: The system automatically initializes a global variable whereas we need to initialize
local variables explicitly.

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

A. 0
B. Garbage

Answer: B) Garbage

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

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

A. auto
B. extern

C. register

D. static

Answer: A) auto
Explanation: The "auto" is the default storage class in C++.

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

A. True

B. False
Answer: A) True

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

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

A. %”

B. /”
C. *”

D. None of the above

Answer: B) /”

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

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

A. %%

B. /%

C. *%
D. None of the above

Answer: A) %%

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

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

A. Arguments that cannot be passed to the function


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

C. Arguments that always take the same data value

D. 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.
71. Which of the following condition is correct for the default arguments?

A. Default arguments must be the last arguments in the function declaration.

B. Default arguments must be the first argument in the function declaration.

C. Default arguments can be declared anywhere in the function declaration.


D. 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.

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

A. int print(int count, char ch='*')


B. int print(char ch='*')

C. int print(char ch='*',int count)

D. int print(char ch)

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


Explanation: In the above options, option B is correct.

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

A. void printchar(int cnt=0, char ch, int val=0)

B. void printchar(int cnt=0, char='*')


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

D. void printchar(char ch='c', int cnt)

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


Explanation: In the above options, option C is correct.

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

B. void sample(int x=0, int y, int z)

C. float sample(int x=0, y=0, z=0)


D. 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.

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

A. sample(10,20,30);

B. sample();

C. sample(50);
D. sample(30,40);

Answer: B) sample();

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


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

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

B. Default arguments are allowed in the return type of the function declaration.

C. Default arguments are allowed with the class name definition.


D. 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.

77. Which of the following statement is not correct about Default arguments?
A. Default arguments are allowed with pointer and reference to function declaration.

B. Default arguments are not allowed with a declaration of a pointer to functions.

C. Default arguments are not allowed with the reference to functions.


D. 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.

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

A. True

B. False

Answer: A) True
Explanation: Yes, the default argument gets bound during declaration but is executed during the
function call.
79. Can we implement a constructor with a default argument?

A. True

B. False

Answer: A) True
Explanation: Yes, we can implement a constructor with a default argument.

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

A. 6

B. 5
C. 4

D. 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

25
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:
A. 1 and 2

B. 1 and 3

C. 4

D. 1, 2, and 3
Answer: D) 1, 2, and 3

Explanation: In C++, Decision-making statements are:

• IF statements
• Switch Statements

• Conditional operators.

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

A. while loop
B. do-while loop

C. for loop

D. conditional operator

Answer: D) conditional operator


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

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

A. if
B. if-else

C. if-else-if

D. All the above

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

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

A. True

B. False
Answer: B) False

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

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


A. While Loop

B. 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.

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


A. While Loop
B. Do While loop

C. For loop

D. 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.

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

A. Do While loop
B. For loop

C. While loop

D. None of the above

Answer: A) Do While loop


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

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

A. Do While loop

B. For loop

C. While loop
D. 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.

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

A. int, float, char

B. int, char

C. int, double
D. Any fundamental type

Answer: A) int, float, char

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

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

A. True

B. False

Answer: A) True
Explanation: Yes, the Expression in parenthesis "()" after the switch statement is mandatory.

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

A. The break statement cancels the remaining iterations


B. Break statement skips a particular iteration

C. The break statement terminates the program

D. None of the above

Answer: A) The break statement cancels the remaining iterations


Explanation: The Break statement cancels the remaining iterations

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

A. Do While loop

B. For loop
C. While loop

D. All loops work at the same speed

Answer: D) All loops work at the same speed


Explanation: All loops work at the same speed.
93. Which of the following statement is used to quit the loop immediately?

A. continue

B. break
C. while

D. None of the above

Answer: B) break

Explanation: The break statement is used to quit the loop immediately.

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

A. selective statement
B. choose statement

C. bitwise statement

D. certain statement

Answer: A) selective statement


Explanation: The switch statement is also known as the selective statement.

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

A. goto statement

B. bitwise statement
C. skipping statement

D. certain statement

Answer: C) skipping statement


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

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

A. for(condition; increment; declaration){ //body of the loop };

B. for(declaration; increment/decrement; condition){ //body of the loop };


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

D. None of the above

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

Explanation: The 3rd option is correct.

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

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


B. dowhile(condition){ //Body of the loop };

C. do while(condition){ //Body of the loop };

D. do{ //Body of the loop }while(condition)

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


Explanation: The 1st option is correct.

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

A. @

B. :
C. #

D. !

Answer: B) :
Explanation: The colon ":" symbol is used with the label in the "goto" statement.

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

A. While loop

B. For loop
C. Do while loop

D. 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.

31
100. Execution of C++ program starts from?

A. void function
B. class

C. main function

D. user-defined function

Answer: C) main function


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

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

A. Semicolon

B. Colon
C. Comma

D. None of the above

Answer: C) Comma
Explanation: The semicolon is used to complete the function declaration.

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

A. 128

B. 256
C. 512

D. 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.

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

A. Function name and argument list


B. Function name and return type

C. Function name, argument list, and return type

D. 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.

33
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:

A. Hello World

B. Hello
C. Error

D. 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;
}

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

A. Yes
B. 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.

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

A. Call by value
B. Call by reference

C. Call by address

D. 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.

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

B. 2

C. 3
D. 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.

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

A. Within the function only


B. Within the main function only

C. Whole program

D. 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.
109. Which of the following statement is correct about inline function?

A. A function that is substituted at the place of call.

B. A function that is called at compile time

C. A function that contains only looping statements


D. 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.

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

B. False

Answer: A) True
Explanation:
Yes, A function that is defined inside a class without any complex statement will be inline.

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

A. Compile Time
B. Runtime

Answer: A) Compile Time

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

36
112. A recursive function can be inline?

A. Yes
B. No

Answer: B) NO

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

113. An inline function can contain static variables?


A. Yes

B. No

Answer: B) NO

Explanation: An inline function cannot contain static variables.


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

A. Yes

B. 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.
115. Default values for a function are defined.

A. In function declaration

B. In function definition
C. During function call
D. None of the above

Answer: A) In function declaration

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

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

A. Yes
B. No

Answer: A) Yes

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

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


A. Yes

B. 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.

118. Index of an array starts from?


A. 1

B. 2

C. 0

D. -1
Answer: C) 0

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

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


A. The base address of the array
B. The first value of the array

C. Last value of the array

D. None of the above


Answer: A) The base address of the array

Explanation: Array name denotes the base address of the array.

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

A. Arr[0]

B. 0[Arr]

C. *(Arr+0)
D. 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.
121. Can we create an array of objects in C++?

A. Yes

B. No

Answer: A) Yes
Explanation: Yes, we can create an array of objects in C++.

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

A. Yes

B. No
Answer: A) Yes

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

123. An array occupies memory space in?

A. Contiguous manner

B. Fragmented manner
C. Linked List

D. None

Answer: A) Contiguous manner

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

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

A. 1D array
B. 2D Array

C. 3D array

D. No Limit

Answer: D) No Limit
Explanation: There is no limit of dimensions for arrays in C++.

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

A. Call by value

B. Call by reference
C. Both A and B

D. 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".

126. Which of the following statement is correct about the is_array() function in C++??
A. The is_array() function is used to check whether a variable is an array or not.

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

C. The is_array() function is used to check whether a variable is a 1D or 2D array.


D. 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.

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

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


B. The is_same() function is used to check if two variables of array type.

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

D. 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.

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

A. getdimension
B. getarraydimension

C. rank

D. arrayrank

Answer: C) rank
Explanation: The rank function is used to get the dimensions of the given array.

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

A. remove_dimension
B. remove_all_dimensions

C. remove_extent

D. remove_all_extents

Answer: D) remove_all_extents
Explanation: The remove_all_extents is used to remove all dimensions from an array.

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

A. std namespace
B. <iostream>

C. <array>

D. None of the above

Answer: A) std namespace


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

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

A. True

B. False

Answer: A) True
Explanation: Yes, the size of the array is not required when we initialize an array as part of the
definition.

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


A. ->

B. &

C. *
D. None of the above

Answer: C) *

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

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


A. ->

B. &

C. *

D. None of the above


Answer: A) ->

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


42
134. Which of the following is invalid?

A. string str, *ptr=0;


B. int a, float *f = &a;

C. int *ptr;

D. 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.
135. Can we point to a datatype using a pointer?

A. True

B. False

Answer: B) False
Explanation: No, we cannot point to a datatype using a pointer.

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

A. int *ptr;

B. int* ptr;
C. int &ptr;

D. int *ptr=0;

Answer: C) int &ptr;


Explanation: The 3rd option is the incorrect way to declare a pointer.
137. A pointer can be initialized with?

A. Address of variable of the same type

B. NULL
C. 0

D. 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.
43
138. Which of the following is the correct way to get value from pointer "ptr"?

A. ptr
B. &ptr

C. *ptr

D. All the above

Answer: C) *ptr
Explanation: The "*ptr" is the correct way to get the value from the pointer ptr.

139. What is the size of a pointer?

A. 4 bytes

B. 8 bytes
C. 16 bytes

D. 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.

140. Which of the following is the correct option?


int* a, b;

A. a is a pointer to an integer and b is an integer variable


B. b is a pointer to an integer and a is an integer variable

C. 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.

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


A. Yes

B. No

Answer: A) Yes

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

44
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:

A. 50
B. 20

C. Address

D. 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.

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

A. Yes
B. 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.

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

A. Far pointer
B. Null pointer

C. Void pointer

D. 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.
145. What is the size of a far pointer?

A. 16-bit

B. 32-bit

C. 64-bit
D. None of the above

Answer: B) 32-bit

Explanation: The size of a far pointer is 32-bit.

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

B. No

Answer: A) Yes
Explanation: Yes, we can access memory outside the current segment using a far pointer.
147. Which of the following is the incorrect type of pointer in C++?

A. Near

B. Far
C. Huge

D. Small

Answer: D) Small

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

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

A. Yes
B. 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.

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

A. unique_ptr
B. shared_ptr

C. week_ptr

D. far_ptr

Answer: D) far_ptr
Explanation: The "far_ptr" is not the correct type of smart pointer in C++.

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

A. Yes

B. No
Answer: B) NO

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

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

B. count()

C. ptr_count()
D. shared_count()

Answer: A) use_count()

Explanation: The use_count() function is used to maintain a reference counter with a


"shared_ptr" smart pointer.

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

A. Stack
B. Heap

C. Static

D. Program code

Answer: B) Heap
Explanation: When we use dynamic memory allocation, memory is allocated in the heap
segment.
153. Which of the following is/are used for dynamic memory allocation?

1. malloc

2. calloc

3. new
4. free

Options:

A. 1 and 2

B. 1, 2, and 4
C. 2 and 3

D. 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++.

154. Can we allocate memory for an object dynamically?


A. Yes

B. No

Answer: A) Yes

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

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

A. Yes

B. No

Answer: B) No
Explanation: We need to manually deallocate the dynamically allocated memory using free()
and delete operator in our program.
156. Which of the following operator is used to release dynamically allocated memory
space?

A. new
B. remove

C. release

D. delete
Answer: D) delete

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

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

A. Yes
B. No

Answer: B) No

Explanation: No, "new" is an operator in C++, which is used to allocate memory space
dynamically.
158. When we allocate memory space for an object using "new", will it call a constructor?

A. Yes
B. 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.

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

A. NULL
B. -1

C. bad_alloc exception

D. None of these

Answer: C) bad_alloc exception


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

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

A. Yes

B. No
Answer: A) Yes

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

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

B. 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.

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

A. int *ptr = new int(111);


B. int *ptr = NULL;ptr = new int; *ptr=111;

C. int *ptr;ptr = new int; *ptr=111;

D. All the above

Answer: D) All the above


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

50
163. Which of the following is correct?

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


B. "ptr = calloc(a, b)" is equivalent to ptr = malloc(a * b);

C. "ptr = calloc(a, b)" is equivalent to ptr = malloc(a); memset(ptr, 0, a);

D. "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.

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:

A. Memory leak
B. Dangling pointer

C. Compiler error

D. 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.

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

A. A language that uses global variables

B. A language that supports dynamic scoping

C. A language that allows dynamic data structures


D. 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.

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

A. Class is an instance that contains data member and member functions.


B. Class is fundamental that contains data member and member functions.

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

D. 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.

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

B. Semicolon.
C. Scope Resolution operator.

D. None of the above


Answer: B) Semicolon.

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

52
168. Can we define member functions outside the class?

A. Yes
B. No

Answer: A) Yes

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

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

B. Semicolon.

C. Scope Resolution operator.

D. None of the above


Answer: C) Scope Resolution operator.

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

170. By default, members of a class are:

A. Public

B. Private
C. Protected

D. None of the above

Answer: B) Private
Explanation: By default, members of a class are private in C++.
171. Can we define a constructor inside the structure?

A. Yes

B. No
Answer: A) Yes

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

53
172. By default, members of a structure are:

A. Public
B. Private

C. Protected

D. None of the above

Answer: A) Public
Explanation: By default, members of a structure are public in C++.

173. Can we define a destructor inside the structure?

A. Yes

B. No
Answer: A) Yes

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

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


A. 1 Byte

B. 0 Byte

C. 2 Byte

D. 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.
175. Can we create multiple objects of a class in C++?

A. Yes

B. No
Answer: A) Yes

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

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

A. .

B. ->

C. :
D. None of the above

Answer: A) .

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

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

A. .

B. ->
C. :

D. 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++.

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


A. Yes

B. No
Answer: A) Yes

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

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

A. Yes
B. 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.

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

A. Yes
B. 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.

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

A. Yes

B. 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++.

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

A. 1
B. 2

C. 3

D. 4

Answer: C) 3
Explanation: There are 3 types of specifiers used in class are given below:

1. Public

2. Private

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

A. Abstract class

B. Concrete class
C. Both A and B

D. None of the above

Answer: C) Both A and B

Explanation: Abstract and concrete are the correct types of classes.


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

A. Yes

B. 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;

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

A. A constructor is used to destroy an object.


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

C. Constructor is used to call the private function from outside the class.

D. 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.
186. How many parameters can be accepted by a default constructor?

A. 1

B. 2

C. 0
D. Infinite

Answer: C) 0

Explanation: A default constructor accepts 0 parameters.

187. What is the return type of a constructor?


A. void

B. int

C. float
D. None of the above
Answer: D) None of the above

Explanation: A constructor does not have any return type.

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

A. Copy constructor
B. Move constructor

C. Default constructor

D. Parameterized constructor

Answer: B) Move constructor


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

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

A. Copy constructor

B. Default constructor

C. Parameterized constructor
D. 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.

190. Can we overload the constructor in a class?

A. Yes
B. No

Answer: B) No

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

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


A. Yes

B. No

Answer: A) Yes

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

59
192. A default constructor is also known as a?

A. Parameterized constructor
B. Copy constructor

C. No argument constructor

Answer: C) No argument constructor

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


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?

A. Linker error

B. Compilation error
C. Logical error

D. None of the above

Answer: B) Compilation error

Explanation: It will generate a compilation error.


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

B. 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.

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

A. ~
B. !

C. $

D. #

Answer: A) ~
Explanation:

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

196. Can we create multiple destructors in class?

A. Yes
B. No

Answer: B) No

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


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

A. Yes

B. 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.
198. Can we create a virtual destructor in a class?
A. Yes

B. No

Answer: A) Yes
Explanation:

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

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

A. Default constructor

B. Dynamic constructor

C. Copy constructor
D. None of the above

Answer: C) Copy constructor

Explanation:Copy constructor is used to create an object by initialize data members using


existing object.

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

A. Yes
B. No

Answer: B) No

Explanation: No, we cannot implement copy constructor without passing a reference of an


object into it.

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

A. Const constructor

B. Default constructor
C. Member initializer list

D. Copy constructor
Answer: C) Member initializer list

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

62
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?

A. Compiler

B. Linker

C. Loader
D. 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.

203. When does a destructor gets called?

A. When an object gets created


B. When an object gets destroyed

C. After calling constructor

D. None of the above

Answer: B) When an object gets destroyed


Explanation: A destructor gets called when an object is getting destroyed.

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

A. True

B. 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.

63

You might also like