Unit 1 - Practice Quiz

CSE202

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

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

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. Algorithms
B. Data
C. Functions
D. Hardware

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

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

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

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

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

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

7 Which of the following best describes a Class?

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

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

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

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

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

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

A. A class with only static members
B. A user-defined type consisting of named integral constants
C. A type of pointer
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. Slower execution
B. Increases binary executable size
C. Cannot access class members
D. Increases function call overhead

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

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

16 Where must a static data member be initialized?

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

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

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

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

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

19 Which standard stream is meant for error messages?

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

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

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

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

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

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

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

23 What does the manipulator 'endl' do?

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

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

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

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. extern variableName
C. ::variableName
D. this->variableName

27 What is a 'Friend Function'?

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

28 Which statement about Friend Classes is true?

A. Friendship is mutual
B. Friendship is inherited
C. Friendship is not mutual and not inherited
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 the value
C. By passing an alias (reference) to the actual argument
D. By passing a pointer

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

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

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

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

35 Can a member function of a class be recursive?

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

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

A. Global scope
B. Function scope
C. Block scope (inside the loop only)
D. File 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. 0 bytes
B. 1 byte
C. 2 bytes
D. 4 bytes

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

48 How is a Class different from an Object?

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

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

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

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

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