Unit 2
Unit 2
VARIABLES
Answer: A
Answer: C
Answer: C
Answer: C
Answer: B
6. Which of the following operators is used to find the size of a data type in C++?
- A) size of
- B) size
- C) lengthof
- D) length
Answer: A
Answer: C
Answer: B
Answer: A
Answer: B
KEYWORDS
Answer: A
Answer: A
Answer: A
Answer: A
Answer: B
Answer: D
Answer: C
Answer: D
Answer: A
Answer: A
TYPECASTING
Answer: B
Answer: D
Answer: A
Answer: A
Answer: B
Answer: A
Answer: A
Answer: B
Answer: D
10. What happens if you try to typecast a pointer to a non-related data type using 'static_cast'?
- A) It is allowed
- B) Generates a compilation error
- C) Results in a runtime error
- D) Automatically adjusts the pointer size
Answer: B
ITERATION
Answer: B
Answer: B
Answer: C
Answer: B
Answer: C
Answer: A
7. Which loop structure is suitable when the number of iterations is known beforehand in C?
- A) while
- B) do-while
- C) for
- D) switch
Answer: C
Answer: A
Answer: A
10. What is the primary difference between 'while' and 'do-while' loops in C++?
- A) Syntax
- B) Performance
- C) The condition is checked before or after the loop body
- D) They are identical
Answer: C
ENUMERATION
Answer: B
Answer: A
3. What is the default starting value of the first element in an enumeration in C++?
- A) 0
- B) 1
- C) 10
- D) -1
Answer: A
4. How can you explicitly set values for elements in a C++ enumeration?
- A) Using the 'set' keyword
- B) Using the 'values' keyword
- C) Assigning values within curly braces
- D) Enumerations cannot have explicit values
Answer: C
Answer: B
Answer: B
7. In C++, can you assign a value to an enumeration element that is not explicitly defined?
- A) Yes, it is allowed
- B) No, it results in a compilation error
- C) Only if the element is at the end of the enumeration
- D) Only if the element is the first in the enumeration
Answer: A
Answer: A
10. What is the purpose of the 'sizeof' operator when used with an enumeration in C++?
- A) To find the size of the enumeration
- B) To find the size of an element in the enumeration
- C) To find the number of elements in the enumeration
- D) To find the total size of the enumeration and its elements
Answer: A
C PREPROCESSORS
POINTERS
pointer by 1 in C++?
- A. The address increases by 1 byte
- B. The address increases by the size of the data type
- C. The address decreases by 1 byte
- D. The address remains the same
- Answer: B. The address increases by the size of the data type
7. What is the purpose of the `const` keyword when used with pointers in C++?
- A. It makes the pointer constant
- B. It makes the pointed value constant
- C. It makes both the pointer and pointed value constant
- D. It has no effect on pointers
- Answer: C. It makes both the pointer and pointed value constant
INHERITANCE
3. What is the access specifier used to indicate that a member of a base class is accessible in
the derived class, but not from outside?
- A. public
- B. private
- C. protected
- D. internal
- Answer: C. protected
5. What is the term used to describe the ability of a class to provide methods that have the
same name but different implementations?
- A. Polymorphism
- B. Overloading
- C. Inheritance
- D. Encapsulation
- Answer: B. Overloading
6. What is the purpose of the virtual keyword in C++ in the context of inheritance?
- A. Declares a member variable
- B. Declares a pure virtual function
- C. Specifies that a function can be overridden
- D. Indicates a static member function
- Answer: C. Specifies that a function can be overridden
8. Which type of inheritance allows a class to inherit from multiple classes but with no
common base class?
- A. Hierarchical inheritance
- B. Multiple inheritance
- C. Single inheritance
- D. Hybrid inheritance
- Answer: B. Multiple inheritance
9. What is the term used to describe a class that cannot be instantiated and is meant only for
deriving other classes?
- A. Abstract class
- B. Concrete class
- C. Final class
- D. Base class
- Answer: A. Abstract class
10. In C++, can a derived class access private members of its base class?
- A. Yes, always
- B. No, never
- C. Yes, if the base class is abstract
- D. Yes, if friend functions are used
- Answer: B. No, never
POLYMORPHISM
3. What is the purpose of the virtual keyword when used with functions in C++?
- A. Declares a static function
- B. Declares a pure virtual function
- C. Indicates that a function can be overridden
- D. Specifies a friend function
- Answer: C. Indicates that a function can be overridden
5. What is the term for having multiple methods in a base class with the same name but
different implementations in derived classes?
- A. Function overloading
- B. Function overriding
- C. Function hiding
- D. Function masking
- Answer: B. Function overriding
6. Which keyword is used to declare a pure virtual function in C++?
- A. abstract
- B. virtual
- C. pure
- D. none of the above
- Answer: C. pure
7. In C++, can a pure virtual function have a definition in the abstract base class?
- A. Yes, always
- B. No, never
- C. Yes, but only if it has a body
- D. Yes, if it is private
- Answer: B. No, never
8. What is the term for the ability of a function to operate on different types or numbers of
arguments?
- A. Function overloading
- B. Function overriding
- C. Operator overloading
- D. Template function
- Answer: D. Template function
ABSTRACTION
Answer: D. class
6. What is the term for providing a common interface for a group of related classes without
specifying their concrete implementations?
- A. Encapsulation
- B. Inheritance
- C. Abstraction
- D. Polymorphism
- Answer: C. Abstraction
9. What is the purpose of the keyword `final` in C++ in the context of abstraction?
- A. Marks a class as abstract
- B. Marks a class as non-abstract
- C. Prevents a class from being subclassed
- D. Indicates the end of a class definition
- Answer: C. Prevents a class from being subclassed
10. What is the term for hiding the details of how an object is implemented and only exposing
the necessary interfaces?
- A. Abstraction
- B. Encapsulation
- C. Polymorphism
- D. Inheritance
- Answer: B. Encapsulation
ENCAPSULATION
4. In C++, can you access private members of a class outside the class?
- A. Yes, always
- B. No, never
- C. Yes, if using friend functions
- D. Yes, if using public functions
- Answer: B. No, never
7. In encapsulation, what is the term used for providing a public method to access private data
members?
- A. Getter method
- B. Setter method
- C. Wrapper method
- D. Encapsulator method
- Answer: A. Getter method
8. What is the potential drawback of using too many friend functions in a class?
- A. Improved encapsulation
- B. Reduced code modularity
- C. Enhanced data hiding
- D. Better code readability
- Answer: B. Reduced code modularity
9. Which access specifier in C++ allows members to be accessed by the derived classes?
- A. public
- B. private
- C. protected
- D. internal
- Answer: C. protected
OPERATING SYSTEM
4. Which scheduling algorithm assigns a fixed time unit per process, regardless of its
execution status?
- A. Round Robin
- B. First-Come-First-Serve (FCFS)
- C. Shortest Job Next (SJN)
- D. Priority Scheduling
- Answer: A. Round Robin
6. Which memory allocation method allows memory blocks to be allocated and deallocated in
any order, minimizing memory fragmentation?
- A. Fixed Partitioning
- B. Dynamic Partitioning
- C. Paging
- D. Segmentation
- Answer: C. Paging
8. Which file system is widely used in Unix and Linux operating systems?
- A. NTFS
- B. FAT32
- C. Ext4
- D. HFS+
- Answer: C. Ext4
10. Which process scheduling algorithm gives priority to the process with the highest priority
value?
- A. Round Robin
- B. First-Come-First-Serve (FCFS)
- C. Shortest Job Next (SJN)
- D. Priority Scheduling
- Answer: D. Priority Scheduling
4. Which protocol is commonly used for file sharing in a Network Operating System
environment?
- A. HTTP
- B. FTP
- C. SMTP
- D. SNMP
- Answer: B. FTP
6. Which NOS model allows users to run applications on a remote server while interacting
with them locally?
- A. Peer-to-Peer (P2P)
- B. Client-Server
- C. Hybrid
- D. Distributed
- Answer: B. Client-Server
8. Which NOS characteristic ensures data integrity and security during network
communication?
- A. Network Monitoring
- B. Encryption
- C. File Compression
- D. Bandwidth Allocation
- Answer: B. Encryption
10. Which type of network is most suitable for a Network Operating System?
- A. Isolated network
- B. Peer-to-peer network
- C. Local Area Network (LAN)
- D. Standalone computer
- Answer: C. Local Area Network (LAN)
DATA STRUCTURES
2. Which data structure follows the Last In, First Out (LIFO) principle?
- A. Queue
- B. Stack
- C. Linked List
- D. Tree
- Answer: B. Stack
6. Which data structure is used for fast retrieval of data from a collection, based on a key?
- A. Array
- B. Stack
- C. Queue
- D. Hash Map
- Answer: D. Hash Map
7. What is the time complexity of searching for an element in a sorted array using binary
search?
- A. O(1)
- B. O(log n)
- C. O(n)
- D. O(n^2)
- Answer: B. O(log n)
10. Which data structure is commonly used for representing a hierarchical relationship
between elements?
- A. Linked List
- B. Stack
- C. Queue
- D. Tree
- Answer: D. Tree
ARRAYS
5. In an array, what is the term used to represent the maximum number of elements it can
hold?
- A. Size
- B. Length
- C. Capacity
- D. Index
- Answer: B. Length
7. What is the term used for an array where elements are stored in contiguous memory
locations?
- A. Linked Array
- B. Contiguous Array
- C. Sequential Array
- D. Random Array
- Answer: C. Sequential Array
9. In arrays, what is the term used for the process of rearranging elements to a more random
order?
- A. Shuffling
- B. Sorting
- C. Reversing
- D. Swapping
- Answer: A. Shuffling
10. Which data structure can be considered as a dynamic version of an array with variable
size?
- A. Linked List
- B. Queue
- C. Array List
- D. Stack
- Answer: C. Array List
STACKS
2. Which principle does a stack follow for element insertion and removal?
- A. First In, First Out
(FIFO)
- B. Last In, First Out (LIFO)
- C. Random Order
- D. Priority-based Order
- Answer: B. Last In, First Out (LIFO)
3. What is the operation called when an element is added to the top of the stack?
- A. Pop
- B. Push
- C. Insert
- D. Remove
- Answer: B. Push
8. What happens when you try to pop an element from an empty stack?
- A. Stack Overflow
- B. Stack Underflow
- C. Memory Leak
- D. Compilation Error
- Answer: B. Stack Underflow
9. In the context of function calls, what does a stack maintain?
- A. Variable declarations
- B. Function parameters
- C. Return addresses
- D. All of the above
- Answer: D. All of the above
QUEUE
2. Which principle does a queue follow for element insertion and removal?
- A. First In, First Out (FIFO)
- B. Last In, First Out (LIFO)
- C. Random Order
- D. Priority-based Order
- Answer: A. First In, First Out (FIFO)
3. What is the operation called when an element is added to the rear of the queue?
- A. Pop
- B. Push
- C. Enqueue
- D. Dequeue
- Answer: C. Enqueue
8. What happens when you try to dequeue an element from an empty queue?
- A. Queue Overflow
- B. Queue Underflow
- C. Memory Leak
- D. Compilation Error
- Answer: B. Queue Underflow
9. In a priority queue, how are elements arranged for removal based on priority?
- A. In ascending order
- B. In descending order
- C. Based on a fixed order
- D. Based on priority levels assigned to elements
- Answer: D. Based on priority levels assigned to elements
2. What is the advantage of a circular linked list over a linear linked list?
- A. Simplicity of implementation
- B. Ease of traversal
- C. Ability to efficiently rotate elements
- D. Efficient reversal of elements
- Answer: C. Ability to efficiently rotate elements
3. In a circular linked list, what does the last node point to?
- A. The first node
- B. NULL
- C. The previous node
- D. Itself
- Answer: A. The first node
4. Which operation is used to add a new node at the end of a circular linked list?
- A. Insert
- B. Append
- C. Attach
- D. Connect
- Answer: B. Append
5. What is the time complexity of inserting a node at the beginning of a circular linked list?
- A. O(1)
- B. O(log n)
- C. O(n)
- D. O(n^2)
- Answer: A. O(1)
6. In a doubly circular linked list, each node has a pointer to which nodes?
- A. Only the next node
- B. Only the previous node
- C. Both the next and previous nodes
- D. Neither next nor previous nodes
- Answer: C. Both the next and previous nodes
4. What is the time complexity of removing an element from the rear of a Dequeue?
- A. O(1)
- B. O(log n)
-
C. O(n)
- D. O(n^2)
- Answer: A. O(1)
5. In a Dequeue, what happens when you try to remove an element from an empty queue?
- A. Dequeue Overflow
- B. Dequeue Underflow
- C. Memory Leak
- D. Compilation Error
- Answer: B. Dequeue Underflow
8. Which operation is used to check the element at the front of a Dequeue without removing
it?
- A. PeekFront
- B. FrontView
- C. CheckFront
- D. FrontPeek
- Answer: A. PeekFront
STRINGS