The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
With every final exam there is no doubt that some people will be unsure about their readiness to sit for it and getting some accurate quizzes to help you can give you the grade you want. Take up the C++ final online exam below and see how you would have scored.
Questions and Answers
1.
What function initalizes variables in a class:
A.
CONSTRUCTOR
B.
 Destructor
C.
 Constitutor
D.
 A and B are
Correct Answer
D. Â A and B are
Explanation The correct answer is "A and B are". In object-oriented programming, a constructor is a special type of method that is used to initialize the variables of a class when an object is created. On the other hand, a destructor is a method that is called when an object is destroyed or goes out of scope. Both the constructor and destructor are used to manage the lifecycle of an object and perform necessary initialization and cleanup tasks. Therefore, both A (constructor) and B (destructor) are responsible for initializing variables in a class.
Rate this question:
2.
To include code from the library in the program, such as iostream, a directive would be called up using this command.
A.
 #include ; with iostream.h inside the brackets
B.
 include (iostreamh)
C.
 #include with iostream.h inside the brackets
D.
 include #iostream,h;
Correct Answer
C. Â #include with iostream.h inside the brackets
Explanation The correct answer is #include . This is the correct way to include the iostream library in a C++ program. The other options either have incorrect syntax or use an outdated version of including the iostream library.
Rate this question:
3.
Single line comments explaining code would be preceded like in the following example
A.
 /**
B.
 //
C.
 *//
D.
 /*
Correct Answer
B. Â //
4.
Which line has all reserved words ?
A.
Char, int, float, doubled, short, long, unsigned, signed
B.
 sizeof, const, typedef, static, voided, enum, struct, union
Correct Answer
C. If, else, for, while do, switch, continue, break
Explanation The line "if, else, for, while do, switch, continue, break" has all reserved words. These words are keywords in programming languages that have a predefined meaning and cannot be used as variable names or identifiers. They are used to define control structures and flow of execution in a program.
Rate this question:
5.
What punctuation must each command line have at the end of the line ?
A.
 :
B.
 ,
C.
 !
D.
 ;
Correct Answer
D. Â ;
Explanation Each command line must have a semicolon (;) at the end of the line. This punctuation is used to indicate the end of a command or statement in many programming languages. It is necessary to separate multiple commands or statements on the same line or to terminate a single command or statement. The other punctuation marks listed (colon, comma, and exclamation mark) do not serve this purpose and are not typically used at the end of a command line.
Rate this question:
6.
The C++ language is
A.
 case-sensitive.
B.
Not case-sensitive.
C.
It depends
D.
None of these
Correct Answer
A. Â case-sensitive.
Explanation The correct answer is "case-sensitive" because in C++ language, the uppercase and lowercase letters are treated as distinct and separate. This means that variables, functions, and keywords must be written with the exact same casing when used in different parts of the code. For example, "variable1" and "Variable1" would be considered two different variables in C++. Therefore, it is important to be consistent with the casing of identifiers in order for the code to compile and execute correctly.
Rate this question:
7.
The number 5.9875e17 must be stored in a(n):
A.
 int
B.
Long
C.
Double
D.
Float
Correct Answer
C. Double
Explanation The number 5.9875e17 is a very large number, which cannot be accurately represented by an int or a long data type. Both int and long data types have a limited range and cannot store such a large value. On the other hand, a double data type can store large floating-point numbers with a high precision. Therefore, the number 5.9875e17 must be stored in a double data type.
Rate this question:
8.
Select the correct definition for a string variable.
A.
String mystr;
B.
String mystr[20];
C.
String[20] mystr;
D.
Char mystr[20];
Correct Answer
D. Char mystr[20];
Explanation The correct definition for a string variable is "char mystr[20];". This is because it declares a variable named "mystr" as a character array with a size of 20. In C or C++ programming, a string is represented as an array of characters terminated by a null character. Therefore, using a character array is the appropriate way to define a string variable. The other options are incorrect because they either declare a variable as a string object or an array of string objects, which is not the correct way to define a string variable in this context.
Rate this question:
9.
The sentence "Hello world!" uses _____ elements in a character array.
A.
 10
B.
 11
C.
12
D.
13
Correct Answer
D. 13
Explanation The sentence "Hello world!" uses 13 elements in a character array because it consists of 12 characters (including the space) and an additional element for the null character '\0' that marks the end of the string.
Rate this question:
10.
When you are creating a structure, you need to use the following keyword
A.
Structure
B.
 struct
C.
 object
D.
 record
Correct Answer
B. Â struct
Explanation When creating a structure, the correct keyword to use is "struct". This keyword is used to define a structure in programming languages such as C or C++. It is followed by the structure name and a set of braces to define the members of the structure. The "struct" keyword indicates that we are creating a new structure type.
Rate this question:
11.
Select the correct function definition (NOT prototype) from the list below.
A.
Void intro();
B.
Double sin(double rad);
C.
Int foo(int bar; double baz)
D.
Double pow(double num, int pow);
Correct Answer
D. Double pow(double num, int pow);
Explanation The correct function definition is "double pow(double num, int pow);" because it follows the correct syntax for defining a function. It specifies the return type "double" followed by the function name "pow". It also includes the required parameters inside the parentheses, with the first parameter being of type "double" and named "num", and the second parameter being of type "int" and named "pow".
Rate this question:
12.
Cout can print multiple values or variables in a single command using the following syntax:
A.
 cout
B.
 cout
C.
 cout
D.
 cout
Correct Answer
B. Â cout
13.
Write a for loop that counts from 0 to 5.
A.
For (c = 0; c
B.
For (int c = 0; c
C.
For (c = 0; c < 5; c++)
D.
For (c = 0; c < 5; c++);
Correct Answer
A. For (c = 0; c
Explanation The correct answer is "for (c = 0; c < 5; c++)". This for loop initializes the variable "c" to 0, sets the condition to iterate as long as "c" is less than 5, and increments "c" by 1 after each iteration. This loop will count from 0 to 4, as it stops when "c" becomes equal to 5.
Rate this question:
14.
What does the statement #include do ?
A.
It defines the function iostream.h
B.
 It defines the words TRUE and FALSE
Correct Answer
A. It defines the function iostream.h
Explanation The statement #include is used in C++ programming to include a library or header file in the program. In this case, the statement #include defines the function iostream.h, which is a header file that contains the declarations needed for input and output operations in C++. This allows the program to use functions like cout and cin for input and output.
Rate this question:
15.
Which of the following converts an integer "value" to its ASCII equivalent ?
A.
 atoi(value)
B.
 cout
C.
(char) value
D.
Char (value)
Correct Answer
A. Â atoi(value)
Explanation The function atoi() converts a string representation of an integer to its corresponding integer value. It does not convert an integer value to its ASCII equivalent. Therefore, the given answer is incorrect.
Rate this question:
16.
Which one of the choices would produce the following output ?
A.
Cout
B.
Cout
C.
Cout
D.
 cin >> "Hello World";
Correct Answer
D. Â cin >> "Hello World";
17.
What is the output of the following code?
for (int i=0; i<10; i++); cout << i%2 << " "; }
A.
0 1 2 3 4 5 6 7 8 9
B.
0 2 4 6 8 10 12 14 16 18
C.
1 0 1 0 1 0 1 0 1 0
D.
0 1 0 1 0 1 0 1 0 1
Correct Answer
C. 1 0 1 0 1 0 1 0 1 0
Explanation The code is using a for loop to iterate from 0 to 9. After each iteration, it is printing the value of i%2 followed by a space. Since i is incremented by 1 after each iteration, i%2 will alternate between 0 and 1. Therefore, the output will be 1 0 1 0 1 0 1 0 1 0.
Rate this question:
18.
What is the output of the following code?
for (int a = 1; a <= 1; a++) cout << a++; cout << a;
A.
 22
B.
12
C.
Error
D.
23
Correct Answer
A. Â 22
Explanation The code starts with a = 1 and enters the for loop. Inside the loop, the value of a is printed (which is 1) and then incremented by 1. The loop condition is checked again, but since a is now 2, the loop exits. Finally, the value of a (which is 2) is printed. Therefore, the output is 22.
Rate this question:
19.
For which values of the integer _value will the following code become an infinite loop?
int number=1;
while (true) {
cout << number;
if (number == 3) break;
number += _value; }
A.
 only 0
B.
Only 1
C.
 only 2
D.
Only 1 or 2
Correct Answer
B. Only 1
Explanation In this code, the while loop will continue indefinitely until the condition "number == 3" is met. The variable "number" starts at 1 and increments by the value of "_value" each time through the loop. The only way for the loop to become an infinite loop is if "_value" is set to 1. This is because when "_value" is 1, "number" will continuously increment by 1 and will never equal 3, causing the loop to run indefinitely. Therefore, the code will only become an infinite loop when "_value" is set to 1.
Rate this question:
20.
Inline functions are invoked at the time of
A.
Run time
B.
Compile time
C.
Depends on how it is invoked
D.
Both b and c above
Correct Answer
B. Compile time
Explanation Inline functions are invoked at compile time because they are expanded by the compiler directly into the calling code. This means that there is no function call overhead at runtime, as the code of the inline function is inserted directly into the calling code. Therefore, the invocation of inline functions happens during the compilation process rather than at runtime.
Rate this question:
21.
Every class has at least one constructor function, even when none is declared.
A.
TRUE
B.
FALSE
Correct Answer
A. TRUE
Explanation In object-oriented programming, a constructor is a special method that is called when an object is created. It is responsible for initializing the object's state. In most programming languages, if a class does not explicitly declare a constructor, a default constructor is automatically provided. This default constructor takes no arguments and performs no initialization. Therefore, every class has at least one constructor function, even when none is declared. This ensures that objects of the class can be created and initialized properly.
Rate this question:
22.
How do we define a destructor?
A.
X~() {}
B.
X() {}~
C.
X() ~{}
D.
~X() {}
Correct Answer
C. X() ~{}
Explanation A destructor is defined using the syntax ~X() {}. In this case, the correct answer is X() ~{}. This syntax indicates that the function X() is the destructor for the class X. The destructor is responsible for cleaning up any resources that the object may have acquired during its lifetime, such as closing files or deallocating memory.
Rate this question:
23.
Can constructors be overloaded?
A.
No
B.
Yes
Correct Answer
B. Yes
Explanation Constructors can be overloaded in object-oriented programming languages. Overloading a constructor means having multiple constructors with different parameter lists within the same class. This allows creating objects using different sets of arguments, providing flexibility and customization. Overloaded constructors can have different numbers or types of parameters, enabling the creation of objects with different initial states. Therefore, the correct answer is yes.
Rate this question:
24.
Which of the following below can perform conversions between pointers to related classes?
A.
Cast_static
B.
Dynamic_cast
C.
Static_cast
D.
Cast_dynamic
Correct Answer
C. Static_cast
Explanation Static_cast is a type of casting operator in C++ that can perform conversions between pointers to related classes. It is used to convert pointers or references from one type to another, as long as there is a valid conversion path between the types. Unlike dynamic_cast, static_cast does not perform any runtime type checking and does not require the use of virtual functions. It is mainly used for safe and explicit type conversions, such as converting a base class pointer to a derived class pointer.
Rate this question:
25.
An abstract class can be instantiated.
A.
TRUE
B.
FALSE
Correct Answer
A. TRUE
Explanation An abstract class cannot be directly instantiated, meaning we cannot create objects of an abstract class using the "new" keyword. However, we can create objects of a subclass that extends the abstract class. In other words, an abstract class can be used as a blueprint for creating objects of its subclasses. Therefore, the statement "An abstract class can be instantiated" is true.
Rate this question:
26.
The default access level assigned to members of a class is ___________
A.
Private
B.
Public
C.
Protected
D.
Needs to be assigned
Correct Answer
A. Private
Explanation The default access level assigned to members of a class is private. This means that the members can only be accessed within the class itself and are not accessible from outside the class.
Rate this question:
27.
Which classes allow primitive types to be accessed as objects?
A.
Storage
B.
Virtual
C.
Friend
D.
Wrapper
Correct Answer
D. Wrapper
Explanation Wrapper classes in Java allow primitive types to be accessed as objects. These classes provide a way to wrap primitive data types (such as int, float, boolean, etc.) into an object so that they can be used in situations where objects are required. The wrapper classes provide various utility methods for converting between primitive types and their corresponding wrapper objects, as well as performing operations on them. This allows for more flexibility and functionality when working with primitive types in Java.
Rate this question:
28.
Which of the following below is /are a valid iterator type?
A.
Input Iterator
B.
Backward Iterator
C.
Forward Iterator
D.
Both a and c above
Correct Answer
D. Both a and c above
Explanation Both a and c above are valid iterator types.
An input iterator is used to read values from a sequence and can only be moved forward. It allows multiple passes over the same sequence.
A forward iterator is similar to an input iterator but also allows modification of the values in the sequence.
Therefore, both input iterator (a) and forward iterator (c) are valid iterator types. Backward iterator is not a valid iterator type.
Rate this question:
29.
What is the difference between overloaded functions and overridden functions?
A.
Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding
B.
Redefining a function in a friend class is called function overriding while Redefining a function in a derived class is called a overloaded fucntion.
Correct Answer
A. Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding
Explanation Overloading and overriding are both concepts used in object-oriented programming to define multiple versions of a function. The main difference between them lies in the binding time. Overloading is a dynamic or run-time binding, which means that the decision of which function to call is made during the execution of the program. On the other hand, overriding is a static or compile-time binding, where the decision of which function to call is made at compile-time based on the type of the object. Therefore, the correct answer states that overloading is dynamic or run-time binding, while overriding is static or compile-time binding.
Rate this question:
30.
What is shallow copy?
A.
A shallow copy creates a copy of the dynamically allocated objects too.
B.
A shallow copy just copies the values of the data as they are.
C.
A shallow copy creates a copy of the statically allocated objects too
D.
Both b and c above
Correct Answer
D. Both b and c above
Explanation A shallow copy refers to creating a copy of an object where the values of the data are simply copied as they are. In addition to copying the values, a shallow copy also creates copies of both dynamically allocated objects and statically allocated objects. Therefore, the correct answer is both option b and c above.
Rate this question:
31.
Which of the following library function below by default aborts the program?
A.
Abort()
B.
Terminate()
C.
End()
D.
Exit()
Correct Answer
D. Exit()
Explanation The exit() function by default aborts the program. This function is used to terminate the program and return a value to the operating system. When the exit() function is called, it immediately ends the program execution and any remaining code after the exit() function call will not be executed.
Rate this question:
32.
What defines a general set of operations that will be applied to various types of data?
A.
Template class
B.
Function template
C.
Class template
D.
Both a and c above
Correct Answer
B. Function template
Explanation A function template is a general set of operations that can be applied to various types of data. It allows the user to define a generic function that can be used with different data types, without having to write separate functions for each type. By using a function template, the user can write a single function definition that can be used with different data types, making the code more flexible and reusable. So, the correct answer is function template.
Rate this question:
33.
What happens when a pointer is deleted twice?
A.
It can abort the program
B.
It can cause a failure
C.
It can cause an error
D.
It can cause a trap
Correct Answer
D. It can cause a trap
Explanation Deleting a pointer twice can cause a trap. When a pointer is deleted, the memory it points to is deallocated. However, if the same pointer is deleted again, it attempts to deallocate the same memory location that has already been deallocated. This leads to undefined behavior, which can manifest as a trap. A trap is an exception or error that interrupts the normal execution of a program, causing it to terminate abruptly.
Rate this question:
34.
What is deep copy?
A.
A deep copy creates a copy of the dynamically allocated objects too.
B.
A deep copy just copies the values of the data as they are.
C.
A deep copy creates a copy of the statically allocated objects too
D.
Both b and c above
Correct Answer
A. A deep copy creates a copy of the dynamically allocated objects too.
Explanation A deep copy creates a copy of the dynamically allocated objects too. This means that not only the values of the data are copied, but also any objects that have been created dynamically using memory allocation. This ensures that the copied object is completely independent and separate from the original object, including any dynamically allocated memory. This is in contrast to a shallow copy, which only copies the references to dynamically allocated objects, resulting in multiple objects pointing to the same memory location.
Rate this question:
35.
There is nothing like a virtual constructor of a class.
A.
FALSE
B.
TRUE
Correct Answer
B. TRUE
Explanation The statement "There is nothing like a virtual constructor of a class" is true. In object-oriented programming, a constructor is a special member function that is automatically called when an object is created. However, constructors cannot be declared as virtual in most programming languages. Virtual functions can be overridden by derived classes, but constructors cannot be inherited or overridden. Therefore, there is no concept of a virtual constructor in a class.
Rate this question:
36.
What is the Difference between struct and class in terms of Access Modifier?
A.
By default all the struct members are private while by default class members are public.
B.
By default all the struct members are protected while by default class members are private.
C.
By default all the struct members are public while by default class members are private.
D.
By default all the struct members are public while by default class members are protected.
Correct Answer
C. By default all the struct members are public while by default class members are private.
37.
C++ provides facility to specify that the compiler should match function calls with the correct definition at the run time. This process is called as
A.
Static binding
B.
Dynamic Binding
Correct Answer
B. Dynamic Binding
Explanation Dynamic Binding is the correct answer because in C++, the compiler can match function calls with the correct definition at runtime. This means that the specific function to be executed is determined based on the actual type of the object being referenced or pointed to, rather than the static type of the reference or pointer. This allows for polymorphism and enables the program to choose the appropriate function implementation based on the object's type at runtime.
Rate this question:
38.
Vtables
A.
Creates a static table per class
B.
Creates a static table per object
C.
Creates a dynamic table per class
D.
Creates a dynamic table per object
Correct Answer
A. Creates a static table per class
Explanation Vtables, also known as virtual function tables, are used in object-oriented programming to implement polymorphism. They are used to resolve function calls at runtime when dealing with inheritance and virtual functions.
The correct answer is "creates a static table per class" because vtables are created per class, not per object. Each class that has virtual functions will have its own vtable, which is a static table that contains pointers to the virtual functions of that class. This table is shared by all objects of that class and is used to determine which function to call when a virtual function is invoked.
Rate this question:
39.
The maximum value that an integer constant can have is ____________________.
A.
-3276700%
B.
3276700%
C.
1.7014%
Correct Answer
B. 3276700%
Explanation The maximum value that an integer constant can have is 3276700%.
Rate this question:
40.
C Language came into existence in the year ____________________.
A.
1971
B.
1972
C.
1957
Correct Answer
B. 1972
Explanation C Language came into existence in the year 1972.
Rate this question:
41.
Macros are defined using ___________________ statement.
A.
#define
B.
#include
C.
#if
Correct Answer
A. #define
Explanation Macros are defined using the "#define" statement. This statement is used to define a macro in C and C++ programming languages. It allows developers to define a name or identifier as a replacement for a particular value or code snippet. This helps in simplifying code, improving readability, and making it easier to maintain and modify. The "#define" statement is followed by the macro name and its corresponding value or code.
Rate this question:
42.
____________________ of the following is allowed in a C arithmetic instruction.
A.
[]
B.
{}
C.
()
Correct Answer
C. ()
Explanation The parentheses () are allowed in a C arithmetic instruction. Parentheses are used to specify the order of operations in an arithmetic expression, allowing certain operations to be performed before others. They are used to group subexpressions and control the evaluation order of the arithmetic expression.
Rate this question:
43.
________________ are the ASCII values for number 0-9.
A.
23-45
B.
56-67
C.
48-57
Correct Answer
C. 48-57
Explanation The ASCII values for numbers 0-9 range from 48 to 57.
Rate this question:
44.
In the C Language ‘A’ represents ________________.
A.
A Digit
B.
A Character
C.
An Integer
Correct Answer
B. A Character
Explanation In the C Language, 'A' represents a character. In C, characters are enclosed in single quotes, and 'A' specifically represents the character 'A'. Characters in C are used to represent individual letters, digits, or special symbols. In this case, 'A' is a character and not a digit or an integer.
Rate this question:
45.
To find factorial of A by using while loop, A will be ________________.
A.
A
B.
A>0
C.
A
Correct Answer
B. A>0
Explanation The correct answer is A>0 because in order to find the factorial of a number using a while loop, we need to iterate the loop until the number becomes 0. So, A should be greater than 0 to enter the loop and perform the factorial calculation.
Rate this question:
46.
The goto statement causes control to go to ___________________.
A.
An operator
B.
A label
C.
A variable
Correct Answer
B. A label
Explanation The goto statement causes control to go to a specific location in the code, which is identified by a label. This allows the programmer to jump to a different part of the program, bypassing the normal flow of execution. Using a label as the target of a goto statement can be useful in certain situations, such as breaking out of nested loops or implementing error handling.
Rate this question:
47.
The goto statement causes control to go to ___________________.
A.
And
B.
Or
C.
Not
Correct Answer
A. And
Explanation The goto statement causes control to go to a specific labeled statement within the program. It allows for non-sequential execution of code by transferring control to a different part of the program. This can be useful in certain situations, such as when implementing error handling or creating loops with complex conditions. The "And" option is incorrect because the goto statement does not perform logical operations, but rather controls the flow of execution within the program.
Rate this question:
48.
The Symbol && is read as ____________________.
A.
TRUE
B.
FALSE
C.
Correct Answer
A. TRUE
Explanation The symbol && is read as "and" in programming languages such as C, C++, Java, and JavaScript. It is used to combine two conditions in a logical statement, where both conditions must be true for the overall expression to be true.
Rate this question:
49.
A do while loop is very similar to a while loop.
A.
TRUE
B.
FALSE
Correct Answer
A. TRUE
Explanation A do while loop is similar to a while loop because both are used for repetitive execution of a block of code based on a condition. However, the main difference is that a do while loop always executes the code block at least once, regardless of whether the condition is initially true or false. In contrast, a while loop may not execute the code block at all if the condition is initially false. Therefore, the statement that a do while loop is very similar to a while loop is true.
Rate this question:
50.
The break key word allows you to jump out of any loop at any time.
A.
TRUE
B.
FALSE
Correct Answer
A. TRUE
Explanation The break keyword is used in programming to exit out of a loop prematurely. It allows you to jump out of the loop at any time, regardless of the loop condition. This can be useful when you want to stop the execution of a loop based on a certain condition being met. Therefore, the statement that the break keyword allows you to jump out of any loop at any time is true.
Rate this question:
Quiz Review Timeline +
Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.