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

OOPs Sample MCQ3

The document contains 10 multiple choice questions about C++ keywords, operators, and concepts like polymorphism. Each question has a single correct answer choice. Additionally, there are 5 code snippets with output questions. The code snippets demonstrate concepts like preprocessor directives, continue statements, switch statements, and goto.

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)
18 views6 pages

OOPs Sample MCQ3

The document contains 10 multiple choice questions about C++ keywords, operators, and concepts like polymorphism. Each question has a single correct answer choice. Additionally, there are 5 code snippets with output questions. The code snippets demonstrate concepts like preprocessor directives, continue statements, switch statements, and goto.

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 keyword is used to pass a parameter by reference in a function in C++?

a) byval

b) byref

c) inout

d) const

Answer: b) byref

2. Which keyword is used to allocate memory for an array dynamically in C++?

a) allocate

b) create

c) new

d) malloc

Answer: c) new

3. Which keyword is used to access a base class member from a derived class in C++?

a) super

b) base

c) this

d) parent

Answer: b) base

4.Which keyword is used to mark the end of a case block in a switch statement in C++?

a) end

b) stop

c) break

d) exit

Answer: c) break
5.Which data type is used to store decimal numbers with single precision in C++?

a) int

b) float

c) double

d) long double

Answer: b) float

6. Which operator is used to access the memory address of a variable in C++?

a) *

b) &

c) $

d) #

Answer: b) &

7. Which operator is used to perform logical OR operation in C++?

a) &&

b) ||

c) !

d) |

Answer: b) ||

8. Which keyword is used to define a constant member function in C++?

a) const

b) static

c) final

d) virtual

Answer: a) const

9. Which keyword is used to access the parent class in a derived class in C++?
a) super

b) base

c) this

d) parent

Answer: b) base

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

a) ++

b) +=

c) -=

d) --

Answer: d) --

2 MARKS MCQ

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


#include <iostream>
#define VALUE 10
int main() {
#if VALUE > 5
std::cout << "VALUE is greater than 5";
#else
std::cout << "VALUE is less than or equal to 5";
#endif
return 0;
}
A. VALUE is greater than 5
B. VALUE is less than or equal to 5
C. Error: Invalid syntax in preprocessor directives
D. No output will be displayed

Answer: A. VALUE is greater than 5

2. Which of the following best describes the concept of polymorphism in object-oriented programming?
A. The ability to define multiple methods with the same name but different parameters.
B. The ability to access private data members of a class.
C. The ability to create objects from abstract classes.
D. The ability to override a method in the parent class.

Answer: A. The ability to define multiple methods with the same name but different parameters.

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


#include <iostream>
int main() {
int i = 0;
while (i < 5) {
if (i == 3)
continue;
std::cout << i << " ";
i++;
}
return 0;
}
A. 0 1 2
B. 0 1 2 3 4
C. 0 1 2 3
D. No output will be displayed
Answer: A. 0 1 2
4. . What will be the output of the following C++ code snippet?
#include <iostream>
int main() {
int day = 2;

switch (day) {
case 1:
std::cout << "Sunday";
break;
case 2:
std::cout << "Monday";
case 3:
std::cout << "Tuesday";
break;
default:
std::cout << "Other day";
break;
}
return 0;
}
A. Monday
B. MondayTuesday
C. MondayTuesdayOther day
D. MondayOther day

Answer: C. MondayTuesdayOther day

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


#include <iostream>
int main() {
int i = 0;
for (; i < 5; i++) {
if (i == 3)
goto skip;

std::cout << i << " ";


}
skip:
std::cout << "Skipped";
return 0;
}
A. 0 1 2 3 Skipped
B. 0 1 2 3 4 Skipped
C. 0 1 2 4 Skipped
D. No output will be displayed

Answer: C. 0 1 2 4 Skipped

You might also like