0% found this document useful (0 votes)
54 views10 pages

C++ Multiple Choice Questions

The document contains multiple choice questions (MCQs) covering key concepts in Procedure-Oriented Programming (POP), Object-Oriented Programming (OOP), C++ programming, and functions in C++. Each section includes questions about principles, advantages, and comparisons between programming paradigms, as well as specific C++ syntax and function behavior. The document serves as a study guide for understanding programming concepts and language features.

Uploaded by

bfgiartsnaac
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)
54 views10 pages

C++ Multiple Choice Questions

The document contains multiple choice questions (MCQs) covering key concepts in Procedure-Oriented Programming (POP), Object-Oriented Programming (OOP), C++ programming, and functions in C++. Each section includes questions about principles, advantages, and comparisons between programming paradigms, as well as specific C++ syntax and function behavior. The document serves as a study guide for understanding programming concepts and language features.

Uploaded by

bfgiartsnaac
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/ 10

Multiple Choice Questions (MCQs)

1. Procedure-Oriented Programming (POP):

1. In Procedure-Oriented Programming, the focus is on:


o A) Data
o B) Functions
o C) Objects
o D) Classes
o Answer: B) Functions
2. Which of the following is a disadvantage of Procedure-Oriented Programming?
o A) Data hiding
o B) Code reuse
o C) Difficult to manage as program size increases
o D) Focus on functions
o Answer: C) Difficult to manage as program size increases
3. In POP, how is data typically shared across functions?
o A) Private variables
o B) Local variables
o C) Global variables
o D) Objects
o Answer: C) Global variables
4. Which of the following languages is procedure-oriented?
o A) C++
o B) Java
o C) Python
o D) C
o Answer: D) C
5. Which feature is lacking in Procedure-Oriented Programming?
o A) Function abstraction
o B) Data abstraction
o C) Function overloading
o D) Function calls
o Answer: B) Data abstraction

2. OOP Paradigm:

6. Which of the following is not a principle of OOP?


o A) Inheritance
o B) Encapsulation
o C) Recursion
o D) Polymorphism
o Answer: C) Recursion
7. In OOP, objects are instances of:
o A) Classes
o B) Functions
o C) Methods
o D) Data types
o Answer: A) Classes
8. Which OOP concept focuses on hiding internal details?
o A) Encapsulation
o B) Inheritance
o C) Abstraction
o D) Polymorphism
o Answer: C) Abstraction
9. Which OOP feature allows one class to acquire the properties of another?
o A) Encapsulation
o B) Inheritance
o C) Polymorphism
o D) Abstraction
o Answer: B) Inheritance
10. Which concept allows functions or methods to take many forms?
o A) Encapsulation
o B) Abstraction
o C) Polymorphism
o D) Inheritance
o Answer: C) Polymorphism

3. Advantages of OOP:

11. Which of the following is an advantage of OOP over functional programming?


o A) Function-centric
o B) Global data access
o C) Easier data security through encapsulation
o D) Function calls
o Answer: C) Easier data security through encapsulation
12. Which OOP feature supports code reusability?
o A) Polymorphism
o B) Abstraction
o C) Encapsulation
o D) Inheritance
o Answer: D) Inheritance
13. Which of the following is a feature of OOP that helps to make large programs
more manageable?
o A) Recursion
o B) Inheritance
o C) Looping
o D) Function abstraction
o Answer: B) Inheritance
14. Which of the following concepts of OOP allows dynamic method dispatch?
o A) Abstraction
o B) Polymorphism
o C) Encapsulation
o D) Inheritance
o Answer: B) Polymorphism
15. Which of the following is considered a disadvantage of OOP?
o A) Data security
o B) Complex structure for small programs
o C) Code reuse
o D) Maintainability
o Answer: B) Complex structure for small programs

4. Comparison with Functional Programming:

16. What is the primary focus of functional programming?


o A) Data
o B) Functions
o C) Objects
o D) Classes
o Answer: B) Functions
17. Which programming paradigm is known for its function-centric approach?
o A) OOP
o B) Procedural Programming
o C) Functional Programming
o D) Logical Programming
o Answer: C) Functional Programming
18. In OOP, which feature provides a mechanism to protect data?
o A) Inheritance
o B) Encapsulation
o C) Polymorphism
o D) Recursion
o Answer: B) Encapsulation
19. Which programming approach is more suitable for applications involving real-
world entities?
o A) Functional Programming
o B) Procedural Programming
o C) Object-Oriented Programming
o D) Logical Programming
o Answer: C) Object-Oriented Programming
20. Which of the following is not a characteristic of functional programming?
o A) Pure functions
o B) Immutability
o C) Polymorphism
o D) First-class functions
o Answer: C) Polymorphism

MCQs on Object-Oriented Programming Concepts

1. What is the primary purpose of a class in object-oriented programming? A) To


define a blueprint for creating objects
B) To manage exceptions in the code
C) To store global variables
D) To implement functions

Answer: A) To define a blueprint for creating objects


2. Which of the following best defines an object in the context of object-oriented
programming? A) A data type that can hold multiple values
B) An instance of a class containing attributes and methods
C) A function that performs a specific task
D) A set of rules for organizing code

Answer: B) An instance of a class containing attributes and methods

3. Inheritance allows a new class to inherit characteristics from an existing class.


What is the new class called? A) Superclass
B) Subclass
C) Interface
D) Module

Answer: B) Subclass

4. Which concept allows for the same method name to behave differently based on
the object that is calling it? A) Encapsulation
B) Inheritance
C) Polymorphism
D) Abstraction

Answer: C) Polymorphism

5. Reusability in object-oriented programming is primarily achieved through


which mechanism? A) Functions
B) Inheritance
C) Variables
D) Loops

Answer: B) Inheritance

6. User-defined data types allow programmers to create custom data structures.


Which of the following is an example of a user-defined data type? A) Integer
B) String
C) Class
D) Float

Answer: C) Class

7. In exception handling, which block is used to execute code that may cause an
error? A) catch
B) finally
C) try
D) throw

Answer: C) try

8. Which of the following is NOT a benefit of encapsulation? A) Hiding the internal


state of an object
B) Protecting object integrity by preventing outside interference
C) Allowing multiple classes to share the same methods
D) Simplifying code maintenance

Answer: C) Allowing multiple classes to share the same methods

MCQs on C++ Programming Concepts

1. What is the correct structure of a basic C++ program? A) Functions followed by


variable declarations
B) Preprocessor directives, main function, and return statement
C) Only variable declarations
D) Input statements before any function definitions

Answer: B) Preprocessor directives, main function, and return statement

2. Which of the following is a valid identifier in C++? A) 2ndVariable


B) variable-name
C) myVariable
D) my variable

Answer: C) myVariable

3. Which of the following keywords is used to define a constant in C++? A) constant


B) define
C) const
D) immutable

Answer: C) const

4. Which of the following is NOT a built-in data type in C++? A) int


B) float
C) string
D) char

Answer: C) string

5. What is the result of the expression 5 + 10 * 2 in C++? A) 30


B) 25
C) 15
D) 20

Answer: C) 25

6. In C++, which of the following is used to declare a reference variable? A) &


B) *
C) %
D) #

Answer: A) &
7. Which of the following statements correctly declares a variable in C++? A) int
1stNumber;
B) float number;
C) string my variable;
D) char@character;

Answer: B) float number;

8. What is the purpose of manipulators in C++? A) To perform arithmetic operations


B) To change the format of output
C) To declare new data types
D) To handle exceptions

Answer: B) To change the format of output

9. Which operator is used for the modulus operation in C++? A) /


B) %
C) *
D) +

Answer: B) %

10. Which of the following input statements is used to read a value from the user in
C++? A) scanf
B) cin
C) input
D) read

Answer: B) cin

Given the expression x = (a > b) ? a : b;, what does it represent? A) A traditional if-
else statement
B) A switch-case statement
C) A ternary conditional operator
D) A loop iteration

Answer: C) A ternary conditional operator

MCQs on Functions in C++ and Parameter Passing

1. What is the purpose of function prototyping in C++? A) To define the function


body
B) To declare a function before its actual definition
C) To call a function multiple times
D) To optimize the function

Answer: B) To declare a function before its actual definition

2. Which of the following correctly defines a function in C++? A) void


functionName() { // code }
B) function functionName() { // code }
C) def functionName() { // code }
D) func functionName() { // code }

Answer: A) void functionName() { // code }

3. Which of the following types of functions does not return a value? A) Void
functions
B) Value-returning functions
C) Recursive functions
D) Overloaded functions

Answer: A) Void functions

4. When a function is called with actual parameters passed by value, what


happens? A) The actual parameter is modified in the calling function
B) A copy of the actual parameter is made for the function
C) The function receives a reference to the original variable
D) The original variable becomes inaccessible

Answer: B) A copy of the actual parameter is made for the function

5. In parameter passing by address, which operator is typically used? A) *


B) &
C) %
D) #

Answer: B) &

6. What is a key advantage of passing parameters by reference? A) It creates a copy


of the parameter, preserving the original
B) It reduces memory usage and increases performance by avoiding copies
C) It prevents the function from modifying the argument
D) It is the only way to return multiple values from a function

Answer: B) It reduces memory usage and increases performance by avoiding copies

7. In the context of recursion, what is a base case? A) A condition that causes infinite
recursion
B) The simplest case that can be solved without further recursion
C) A condition that leads to program termination
D) The first recursive call made by a function

Answer: B) The simplest case that can be solved without further recursion

8. What would be the output of the following recursive function call:


factorial(5)?

cpp
Higher-Order Thinking MCQs on Functions and Parameter Passing in C++

1. In the context of function prototyping, why is it necessary to declare a function


before using it in C++? A) To improve performance
B) To inform the compiler about the function's return type and parameters
C) To enable recursive calls
D) To allow for function overloading

Answer: B) To inform the compiler about the function's return type and parameters

2. If a function is defined to take an integer parameter but receives a float value


when called, what will happen in C++? A) The program will compile without issues
B) Implicit conversion will occur, truncating the float
C) A runtime error will occur
D) The compiler will produce an error

Answer: B) Implicit conversion will occur, truncating the float

3. Consider the following function declaration: void updateValue(int &x). What


is the effect of using & in the parameter? A) The original variable cannot be
modified
B) A copy of the variable is passed to the function
C) The function receives a reference to the original variable, allowing modification
D) The function cannot be called with constant variables

Answer: C) The function receives a reference to the original variable, allowing


modification

4. Why is recursion often preferred for solving problems like factorial calculation
or Fibonacci series? A) It uses less memory than iterative solutions
B) It provides a clearer and more elegant solution for problems that have a recursive
structure
C) Recursive solutions are always faster than iterative ones
D) It eliminates the need for function prototypes

Answer: B) It provides a clearer and more elegant solution for problems that have a
recursive structure

5. What happens if the base case is not properly defined in a recursive function? A)
The function will return an undefined value
B) The function may cause a stack overflow due to infinite recursion
C) The program will terminate unexpectedly
D) The function will execute normally but will not return a value

Answer: B) The function may cause a stack overflow due to infinite recursion

6. Given the following function declaration: void process(int value, int


&result);, which statement is true? A) value can be modified within the function
B) result is passed by value, making it immutable
C) Changes to result within the function will affect the original variable passed as
an argument
D) Both parameters are passed by reference

Answer: C) Changes to result within the function will affect the original variable
passed as an argument

7. Which of the following best describes the relationship between function


overloading and parameter types? A) Functions can be overloaded only by return
type
B) Functions can be overloaded by using the same parameter type but different return
types
C) Function overloading allows multiple functions with the same name but different
parameter types or counts
D) Function overloading is only possible with reference parameters

Answer: C) Function overloading allows multiple functions with the same name but
different parameter types or counts

8. In a function that uses both pass-by-value and pass-by-reference, how can you
ensure that the original value of a variable remains unchanged? A) Use only
pass-by-reference for all parameters
B) Use pass-by-value for parameters that should not change
C) Always return a new value from the function
D) Avoid using function prototypes

Answer: B) Use pass-by-value for parameters that should not change

9. If a recursive function is designed to compute a value but does not have a return
type specified, what will the compiler assume? A) The function will be treated as a
void function
B) The function will produce a compilation error
C) The function will return an integer by default
D) The function will return a floating-point number
10.  What is the purpose of the break statement inside a loop? A) To terminate the
program
B) To skip the current iteration and move to the next
C) To exit the loop immediately
D) To continue executing the loop even if the condition fails
11. Answer: C) To exit the loop immediately
12.  In nested loops, what is the effect of using a continue statement? A) It exits
the outer loop
B) It skips the remaining code in the inner loop and continues with the next iteration
of the inner loop
C) It skips the next iteration of the outer loop
D) It causes a compilation error
13. Answer: B) It skips the remaining code in the inner loop and continues with the next
iteration of the inner loop
14.  How does using do-while differ from while when controlling loop execution?
A) do-while checks the condition before executing the loop body
B) do-while guarantees at least one execution of the loop body
C) while cannot be used with complex conditions
D) There is no difference; both are identical in function
15. Answer: B) do-while guarantees at least one execution of the loop body
16.  Which of the following statements best describes the impact of using multiple
conditional expressions? A) It decreases the performance of the program
significantly
B) It can make the code more complex and harder to read if not structured properly
C) It automatically optimizes the code execution
D) It ensures that all conditions will be evaluated regardless of short-circuit evaluation

You might also like