Question : 1 What is the correct syntax to define a function in C++?
function myFunction() {};
void myFunction() {}
def myFunction() {}
def myFunction():
Question : 2 Which data type in C++ is used to store a single character?
char
int
string
float
Question : 3 What is the output of the following code snippet: int x = 5; cout << x++;
5
6
Compiler Error
Undefined Behavior
Question : 4 Which operator is used to allocate memory for a variable in C++?
new
malloc
alloc
allocate
Question : 5 What is the correct way to access the "age" member variable of an object "person" of class "Person" in C++?
person.age;
person->age;
person::age;
person[age];
Question : 6 Which keyword is used to inherit a class in C++?
extend
inherits
extend class
inherit
Question : 7 What is the output of the following code snippet: int x = 10; int y = x++ + ++x; cout << y;
20
21
22
Compiler Error
Question : 8 Which of the following is NOT a valid C++ comment?
// This is a comment
/* This is a comment */
# This is a comment
// This is another comment
Question : 9 What is the purpose of the "endl" manipulator in C++?
It ends the program execution.
It moves the cursor to the next line.
It clears the output buffer.
It inserts a new line character.
Question : 10 What is the function of the "cin" object in C++?
To display output on the console.
To write data to a file.
To read input from the console.
To allocate memory.
Question : 11 What does the "static" keyword mean when used with a class member in C++?
It specifies that the member is accessible only within its class.
It indicates that the member should not be initialized.
It signifies that the member is shared among all objects of the class.
It defines a constant member.
Question : 12 Which operator is used to access the member functions and variables of a class in C++?
->
.
::
:
Question : 13 What is the correct way to declare a reference variable in C++?
int &x = 10;
int* x;
int& x = y;
int x = &y;
Question : 14 What is the output of the following code snippet: int arr[5] = {1, 2, 3}; cout << arr[3];
0
1
2
Undefined Behavior
Question : 15 What does the "sizeof" operator return in C++?
The address of a variable.
The size of a datatype in bytes.
The value of a variable.
The datatype of a variable.
Question : 16 What is the function of the "break" statement in a switch case statement in C++?
To skip the current iteration of a loop.
To exit the switch case block.
To terminate the program execution.
To continue to the next case.
Question : 17 What is the purpose of the "continue" statement in C++?
To exit the loop.
To jump to the next iteration of the loop.
To return from a function.
To print the loop index.
Question : 18 What is the difference between "++i" and "i++" in C++?
"++i" increments the value of i and returns the new value, while "i++" returns the value of i and then increments it.
"++i" increments the value of i, while "i++" decrements it.
"++i" decrements the value of i and returns the new value, while "i++" returns the value of i and then decrements it.
"++i" and "i++" have the same functionality.
Question : 19 What is the output of the following code snippet: int x = 5, y = 10; cout << (x > y ? x : y);
5
10
Compiler Error
10
Question : 20 Which of the following statements is true about the "virtual" keyword in C++?
It is used to declare a pure virtual function.
It specifies that a function can be overridden in derived classes.
It is used to define a function inside a class.
It is used to prevent inheritance.
Question : 21 What is the purpose of the "typeid" operator in C++?
To determine the type of an object at runtime.
To perform dynamic casting.
To perform static casting.
To determine the size of an object.
Question : 22 What is the syntax for creating an object of class "MyClass" using dynamic memory allocation in C++?
MyClass obj();
MyClass obj = new MyClass();
MyClass* obj = new MyClass();
MyClass obj = new MyClass;
Question : 23 What is the purpose of the "friend" keyword in C++?
To specify the base class in inheritance.
To declare a function or class as a friend, granting it access to private and protected members of the class.
To declare a function as a member of a class.
To specify the derived class in inheritance.
Question : 24 Which of the following statements about templates in C++ is true?
Templates are used to define generic classes and functions.
Templates can only be used with built-in data types.
Templates are used to define private members of a class.
Templates are not supported in C++.
Question : 25 What is the difference between "new" and "malloc()" in C++?
"new" is an operator used for dynamic memory allocation and also calls the constructor, while "malloc()" is a function used for dynamic memory allocation without calling the constructor.
"new" is used for static memory allocation, while "malloc()" is used for dynamic memory allocation.
"new" is used for array allocation, while "malloc()" is used for single variable allocation.
"new" is a function used for dynamic memory allocation and also calls the constructor, while "malloc()" is an operator used for dynamic memory allocation without calling the constructor.
Question : 26 What is the purpose of the "delete" operator in C++?
To deallocate memory allocated using "new".
To deallocate memory allocated using "malloc()".
To delete a file from the file system.
To remove an element from a container.
Question : 27 What is the difference between "private" and "protected" access specifiers in C++ classes?
"private" members are accessible only within the same class, while "protected" members are accessible within the same class and its derived classes.
"private" members are accessible within the same class and its derived classes, while "protected" members are accessible only within the same class.
"private" members are accessible from anywhere in the program, while "protected" members are accessible only within the same class.
"private" members are accessible only within the same class, while "protected" members are accessible from anywhere in the program.
Question : 28 What is function overloading in C++?
It refers to the ability to define multiple functions with the same name but different return types.
It refers to the ability to define multiple functions with the same name but different access specifiers.
It refers to the ability to define multiple functions with the same name but different parameter lists.
It refers to the ability to define multiple functions with the same name but in different classes.
Question : 29 What is a constructor in C++?
It is a function that is called when an object is created.
It is a function that is called when an object is destroyed.
It is a function that is called when an object is modified.
It is a function that is called when an object is copied.
Question : 30 What is the purpose of the "this" pointer in C++?
To store the address of the current object.
To store the address of the previous object.
To store the address of the next object.
To store the address of the main function.
Question : 31 What is the difference between "class" and "struct" in C++?
There is no difference between "class" and "struct" in C++.
In a "class", members are private by default, while in a "struct", members are public by default.
In a "class", members are public by default, while in a "struct", members are private by default.
In a "class", members are protected by default, while in a "struct", members are private by default.
Question : 32 What is the purpose of inheritance in C++?
To create multiple instances of a class.
To allow a class to inherit properties and behaviors from another class.
To prevent other classes from accessing certain members of a class.
To restrict the access to certain members of a class.