
Q1
Q1 In OOP, what does encapsulation refer to?
Storing data in arrays
The process of inheritance
Combining data and methods
A type of loop
Q2
Q2 Which concept in OOP allows for the same function to be used in different ways based on the object it is associated with?
Encapsulation
Abstraction
Inheritance
Polymorphism
Q3
Q3 What is the role of comments in a C++ program?
To optimize code execution
To define variables
To provide documentation and explanation
To declare constants
Q4
Q4 What is a variable in C++?
A constant value
A data type
A storage location with a name
A keyword
Q5
Q5 Which data type would be best to store a person's age?
int
double
bool
char
Q6
Q6 What is a constant in C++?
A variable whose value can change
A fixed value that cannot be altered during execution
A type of operator
A special function
Q7
Q7 What is the output of this C++ code?
int main() {
int x = 5;
cout << x;
return 0;
}
0
5
x
Error
Q8
Q8 Identify the error in this C++ code:
int main() {
int 123number;
return 0;
}
Variable name starting with a digit
Incorrect data type
Syntax error in return statement
No error
Q9
Q9 Spot the error in this C++ code:
const int num; num = 10;
cout << num;
Missing variable initialization
Incorrect use of const
Syntax error in cout statement
No error
Q10
Q10 Which operator is used for logical AND in C++?
&&
&
||
==
Q11
Q11 In C++, what is the difference between == and =?
== is used for assignment, while = is used for comparison
== is used for comparison, while = is used for assignment
Both are used for assignment
Both are used for comparison
Q12
Q12 What is the output of the following code?
int a = 1;
int b = 2;
cout << (a++ + b);
3
4
Syntax error
2
Q13
Q13 Pseudocode:
SET a TO 5 IF a > 3 THEN PRINT "Yes" ELSE PRINT "No" What is the output?
Yes
No
Error
None
Q14
Q14 Pseudocode:
SET val TO 7 IF val < 10 AND val > 5 THEN PRINT "In range" ELSE PRINT "Out of range" What is the output?
In range
Out of range
Error
None
Q15
Q15 Pseudocode:
SET num TO 15 SET result TO num DIV 2 PRINT result What does this print?
7.5
7
15
Error
Q16
Q16 Pseudocode:
IF (5 > 3) OR (8 < 6) THEN PRINT "True" ELSE PRINT "False" What is the output?
True
False
Error
None
Q17
Q17 Find the mistake:
int num;
num == 5;
cout << num;
Misuse of equality operator
Undeclared variable
No error
Syntax error in cout statement
Q18
Q18 What is the purpose of the if statement in C++?
To execute a block of code multiple times
To stop the execution of the program
To make a decision
To declare a variable
Q19
Q19 In C++, the do-while loop is unique because it...
executes its block of code at least once
is faster than other loops
does not check a condition
can only run a fixed number of times
Q20
Q20 What is the primary difference between a for loop and a while loop in C++?
Syntax only
While loop can run infinitely, for loop cannot
For loop is used for arrays, while loop is not
Initialization, condition checking, and increment/decrement are part of the for loop statement
Q21
Q21 What happens if the condition in an if statement is false?
The program terminates
The else part is executed
The program skips to the next loop
None of the above
Q22
Q22 What is the output of this code?
int i = 0;
while(i < 3) {
cout << i; i++;
}
012
123
Infinite loop
Syntax error
Q23
Q23 What is the output of the following code?
int x = 10;
do {
cout << x;
x--; } while (x > 10);
Prints 10 once
Prints 10 and then 9
Prints numbers from 10 to 1
No output
Q24
Q24 Pseudocode:
SET i TO 0 WHILE i < 3 DO PRINT i INCREMENT i What does this print?
012
123
Infinite loop
Nothing
Q25
Q25 Identify the error in the code:
int i = 1;
for(; i <= 5; i++) {
cout << i;
}
Missing initialization in for loop
No error
Syntax error in cout statement
Incorrect loop condition
Q26
Q26 What is the purpose of default arguments in function definitions?
To specify what value a function returns
To give a default value to a parameter if no argument is passed
To make a parameter optional
To overload a function
Q27
Q27 How does a recursive function in C++ stop calling itself?
By using a for loop
By reaching a return statement
Through a conditional statement that leads to a return
By calling another function
Q28
Q28 What does this function do?
void printHello() {
cout << "Hello, World!";
}
Prints "Hello, World!" to the console repeatedly
Prints "Hello, World!" once to the console
Does nothing
Causes a runtime error
Q29
Q29 Consider the function:
int multiply(int x, int y) { return x * y; }
What is returned by multiply(5, 4);?
20
9
Syntax error
0
Q30
Q30 Find the error in this function:
int square(int n) {
return n * n;
}
cout << square();
Missing argument in function call
Syntax error in return statement
No return type for function
No error


