Unit 1: Concepts and Basics of C++ Programming and Functions - Practice Quiz

CSE202 — Object Oriented Programming 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which header file is strictly required to use basic input/output operations like cin and cout in C++?

A. <iomanip>
B. <conio.h>
C. <stdio.h>
D. <iostream>

2 Which operator is used with the standard output stream (cout)?

A. <<
B. ::
C. >>
D. ->

3 In C++, what is the main focus of the Object-Oriented Programming paradigm compared to Procedural Programming?

A. Data
B. Functions
C. Algorithms
D. Hardware

4 Which approach is primarily followed in Object-Oriented Programming?

A. Top-down
B. Left-right
C. Linear
D. Bottom-up

5 What is the default access specifier for members of a Class in C++?

A. protected
B. public
C. private
D. static

6 What is the default access specifier for members of a Structure (struct) in C++?

A. public
B. internal
C. protected
D. private

7 Which of the following best describes a Class?

A. A variable referencing an address
B. A blueprint for creating objects
C. A function library
D. A built-in data type

8 What is the process of creating an object from a class called?

A. Polymorphism
B. Instantiation
C. Inheritance
D. Encapsulation

9 How does a Union differ from a Structure regarding memory allocation?

A. Unions allocate memory for all members simultaneously
B. Unions do not allocate memory
C. Unions allocate memory equal to the sum of all members
D. Unions allocate memory equal to the largest member

10 What is an Enumeration (enum) in C++?

A. A type of pointer
B. A user-defined type consisting of named integral constants
C. A class with only static members
D. A function that returns multiple values

11 Which operator is used to access a class member using an object instance?

A. ::
B. :
C. ->
D. .

12 Which operator is used to access a class member using a pointer to an object?

A. &
B. ->
C. .
D. *

13 What is the keyword used to request the compiler to treat a function as an inline function?

A. static
B. inline
C. const
D. register

14 Which of the following is a disadvantage of inline functions?

A. Cannot access class members
B. Slower execution
C. Increases binary executable size
D. Increases function call overhead

15 If a member function is defined inside the class definition, it is treated as?

A. Virtual function
B. Inline function
C. Friend function
D. Static function

16 Where must a static data member be initialized?

A. Outside the class definition
B. Inside the class definition
C. Inside the constructor
D. Inside the main function

17 What is the default initial value of a static integer data member if not explicitly initialized?

A. 0
B. Garbage value
C. Null
D. 1

18 A static member function can access which of the following?

A. Only private members
B. Only non-static members
C. Both static and non-static members
D. Only static members

19 Which standard stream is meant for error messages?

A. cerr
B. cout
C. clog
D. cin

20 Which function is used to read a full line of text, including spaces, from cin?

A. getline()
B. scanf()
C. cin >>
D. read()

21 What rule applies to Default Arguments in a function declaration?

A. Only the first argument can be default
B. They must be assigned from left to right
C. They must be assigned from right to left
D. They can be assigned in any order

22 Which header file is required to use parameterized manipulators like setw()?

A. <iomanip>
B. <string>
C. <fstream>
D. <iostream>

23 What does the manipulator 'endl' do?

A. Inserts a new line and flushes the buffer
B. Clears the screen
C. Inserts a new line only
D. Inserts a null terminator

24 Function overloading allows multiple functions to have the same name if:

A. They have different access modifiers
B. They have different parameter lists (signatures)
C. They are in different files
D. They have different return types only

25 Which operator is known as the Scope Resolution Operator?

A. ->
B. :
C. .
D. ::

26 If a local variable has the same name as a global variable, how do you access the global variable?

A. global.variableName
B. this->variableName
C. ::variableName
D. extern variableName

27 What is a 'Friend Function'?

A. A non-member function that can access private and protected members of a class
B. A function that inherits from the class
C. A function that is a member of the class
D. A function accessible only to derived classes

28 Which statement about Friend Classes is true?

A. Friendship is inherited
B. Friendship is not mutual and not inherited
C. Friendship is mutual
D. Friendship is public by default

29 What is a Reference Variable?

A. A pointer to a memory address
B. An alias or alternative name for an existing variable
C. A variable that holds a constant value
D. A static variable

30 Which of the following syntax correctly declares a reference variable 'ref' for an integer 'a'?

A. int ref = a;
B. int *ref = &a;
C. int ref = &a;
D. int &ref = a;

31 In 'Call by Value', what happens to the actual arguments?

A. Their addresses are passed
B. Their values are copied to formal parameters
C. They are modified by the function
D. Aliases are created

32 In 'Call by Reference', how are arguments passed?

A. By creating a copy
B. By passing an alias (reference) to the actual argument
C. By passing a pointer
D. By passing the value

33 Which method of parameter passing requires the use of pointers in the function definition?

A. Call by value
B. Call by name
C. Call by reference
D. Call by address

34 What is the necessary condition for a recursive function to terminate?

A. A loop
B. A static variable
C. A global variable
D. A base case

35 Can a member function of a class be recursive?

A. Only if it is a friend function
B. Only if it is a static member function
C. No, only global functions can be recursive
D. Yes, member functions can call themselves

36 What is the scope of a variable declared inside a for loop initialization?

A. Global scope
B. File scope
C. Block scope (inside the loop only)
D. Function scope

37 Which symbol allows cascading of input/output operations?

A. ,
B. ::
C. << or >>
D. ;

38 What is the minimal size of an empty class in C++?

A. 4 bytes
B. 2 bytes
C. 0 bytes
D. 1 byte

39 Which feature of OOP allows hiding internal details and showing only functionality?

A. Encapsulation
B. Inheritance
C. Polymorphism
D. Abstraction

40 If a reference variable is declared, must it be initialized immediately?

A. Only if it is static
B. No
C. Yes
D. Only if it is const

41 Which of the following is NOT a characteristic of a static member function?

A. It can access static members
B. It can access non-static members directly
C. It does not have a 'this' pointer
D. It can be called without an object

42 What keyword allows a specific class to access private members of another class?

A. friend
B. extern
C. super
D. virtual

43 Which of the following creates a Manipulator that sets the field width to 10?

A. setfill(10)
B. setprecision(10)
C. setw(10)
D. width(10)

44 In function overloading, which of the following is NOT considered for differentiation?

A. Type of arguments
B. Number of arguments
C. Order of arguments
D. Return type

45 Which memory segment is used to store non-static local variables during recursion?

A. Stack
B. Code Segment
C. Data Segment
D. Heap

46 Can a 'friend' function be declared as 'const' or 'volatile'?

A. Only const
B. Yes
C. No
D. Only volatile

47 What happens if you define a function with default arguments but provide all arguments during the call?

A. The default values are used regardless
B. The provided arguments override the defaults
C. Compiler Error
D. Runtime Error

48 How is a Class different from an Object?

A. Class is a variable; Object is a type
B. They are the same
C. Class is a logical entity; Object is a physical entity
D. Object creates a Class

49 Which statement is true regarding the scope of class members defined as 'private'?

A. Accessible by derived classes
B. Accessible only within the class and by friends
C. Accessible from anywhere
D. Accessible by main() function

50 What is the correct way to define a member function outside the class?

A. ReturnType FunctionName(Params) { ... }
B. friend ReturnType FunctionName(Params) { ... }
C. ClassName.FunctionName(Params) { ... }
D. ReturnType ClassName::FunctionName(Params) { ... }