0% found this document useful (0 votes)
49 views6 pages

OOPs Sample MCQ2

This document contains 10 multiple choice questions that test C++ fundamentals such as operators, control structures, functions, classes, and data types. It also includes 5 additional multiple choice questions that test logical reasoning and code output based on sample C++ code snippets. The questions cover a variety of core C++ concepts to thoroughly assess understanding of the language.

Uploaded by

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

OOPs Sample MCQ2

This document contains 10 multiple choice questions that test C++ fundamentals such as operators, control structures, functions, classes, and data types. It also includes 5 additional multiple choice questions that test logical reasoning and code output based on sample C++ code snippets. The questions cover a variety of core C++ concepts to thoroughly assess understanding of the language.

Uploaded by

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

1. Which operator is used to access a member variable or function of an object in C++?

a) .

b) *

c) ->

d) :

Answer: a) .

2. Which keyword is used to declare a class in C++?

a) class

b) struct

c) typedef

d) typename

Answer: a) class

3. Which data type is used to store single characters in C++?

a) int

b) char

c) float

d) double

Answer: b) char

4. Which preprocessor directive is used to conditionally compile a block of code in C++?

a) #define

b) #include

c) #ifdef

d) #ifndef

Answer: c) #ifdef
5. Which decision-making construct in C++ is used when you have multiple conditions and want to
perform different actions based on each condition?

a) if

b) if-else

c) if-else-if ladder

d) switch case

Answer: d) switch case

6. Which repetitive construct in C++ is primarily used when you want to execute the loop at least once,
even if the condition is false?

a) for loop

b) while loop

c) do-while loop

d) switch case

Answer: c) do-while loop

7. Which operator is used to increment the value of a variable by 1 in C++?

a) ++

b) +=

c) =

d) *

Answer: a) ++

8. Which operator is used to perform logical AND operation in C++?

a) &&

b) ||

c) !

d) &

Answer: a) &&
9. Which keyword is used to stop the execution of the current iteration and move to the next iteration in
a loop in C++?

a) continue

b) break

c) exit

d) return

Answer: a) continue

10. Which keyword is used to define a function in C++?

a) func

b) method

c) def

d) void

Answer: d) void

2 MARK MCQ

1.What will be the output of the following C++ code?


#include <iostream>
int main() {
int x = 5;
int y = 3;
int z = (x > y) ? (x - y) : (y - x);
std::cout << "The result is: " << z << std::endl;
return 0;
}
a) The result is: 2
b) The result is: 3
c) The result is: 5
d) The result is: 8

Answer: a) The result is: 2

2. What will be the output of the following C++ code?


#include <iostream>
int main() {
for (int i = 1; i <= 5; i++) {
if (i == 3) {
continue;
}
std::cout << i << " ";
}
std::cout << std::endl;
return 0;
}
a) The program will compile but no output will be displayed.
b) The program will display "1 2 3 4 5 ".
c) The program will display "1 2 4 5 ".
d) The program will display "1 2 4 ".

Answer: c) The program will display "1 2 4 5 ".

3. What will be the output of the following C++ code?


#include <iostream>
int main() {
int x = 10;
int y = 5;
int z = x++ + --y;
std::cout << "The result is: " << z << std::endl;
return 0;
}
a) The result is: 14
b) The result is: 15
c) The result is: 16
d) The result is: 10

Answer: a) The result is: 14

4. What will be the output of the following C++ code?


#include <iostream>
int main() {
int x = 5;
int y = 10;
int z = 15;
if (x < y && y < z) {
std::cout << "Condition is true" << std::endl;
} else {
std::cout << "Condition is false" << std::endl;
}
return 0;
}
a) The program will compile but no output will be displayed.
b) The program will display "Condition is true".
c) The program will display "Condition is false".
d) The program will display "Condition is true" if x is greater than y.

Answer: b) The program will display "Condition is true".


5. What will be the output of the following C++ code?
#include <iostream>
int main() {
int num = 2;

switch (num) {
case 1:
std::cout << "One" << std::endl;
break;
case 2:
std::cout << "Two" << std::endl;
break;
case 3:
std::cout << "Three" << std::endl;
break;
default:
std::cout << "Other" << std::endl;
}

return 0;
}
a) The program will compile but no output will be displayed.
b) The program will display "One".
c) The program will display "Two".
d) The program will display "Three".

Answer: c) The program will display "Two".

You might also like