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

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

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

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

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

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

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

7 Which of the following best describes a Class?

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

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

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

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

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

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

A. A type of pointer
B. A class with only static members
C. A user-defined type consisting of named integral constants
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. const
B. inline
C. register
D. static

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

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

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

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

16 Where must a static data member be initialized?

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

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

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

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

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

19 Which standard stream is meant for error messages?

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

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

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

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

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

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

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

23 What does the manipulator 'endl' do?

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

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

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

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

27 What is a 'Friend Function'?

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

28 Which statement about Friend Classes is true?

A. Friendship is mutual
B. Friendship is not mutual and not inherited
C. Friendship is 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. They are modified by the function
B. Their addresses are passed
C. Their values are copied to formal parameters
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 address
B. Call by reference
C. Call by name
D. Call by value

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

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

35 Can a member function of a class be recursive?

A. Only if it is a static member function
B. No, only global functions can be recursive
C. Only if it is a friend function
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. Function scope
D. Block scope (inside the loop only)

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. 2 bytes
B. 4 bytes
C. 1 byte
D. 0 bytes

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. Yes
C. Only if it is const
D. No

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

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

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

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

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

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

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

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

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

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

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

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

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

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

48 How is a Class different from an Object?

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

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

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

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

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