




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which programming paradigm emphasizes dividing a program into procedures or routines to promote code reuse and clarity? A) Object-Oriented Programming B) Procedural Programming C) Functional Programming D) Logic Programming Answer: B) Procedural Programming Explanation: Procedural programming structures code into procedures or functions, promoting modularity and reusability, which makes it easier to understand and maintain. Question 2. In C++, which of the following is NOT a core concept of Object- Oriented Programming? A) Encapsulation B) Inheritance C) Polymorphism D) Recursion
Answer: D) Recursion Explanation: Encapsulation, inheritance, and polymorphism are fundamental to OOP, whereas recursion is a general programming technique not specific to OOP. Question 3. Which principle of structured programming involves breaking down a complex problem into simpler sub-problems? A) Encapsulation B) Top-down design C) Data abstraction D) Code reuse Answer: B) Top-down design Explanation: Top-down design involves starting from the highest level of the problem and breaking it down into smaller, manageable modules, promoting clarity and systematic development.
Explanation: Operator precedence dictates multiplication before addition, so 3 * 2 = 6, then 5 + 6 = 11. Question 6. Which control statement in C++ executes a block of code if a condition is true, and an alternative block if false? A) switch B) if-else C) for D) while Answer: B) if-else Explanation: The if-else statement allows executing different blocks based on a condition. Question 7. What is the primary purpose of the break statement in C++ loops and switch statements? A) Exit the current loop or switch early
B) Continue to the next iteration C) Skip the current statement only D) Restart the loop from the beginning Answer: A) Exit the current loop or switch early Explanation: break terminates the nearest enclosing loop or switch statement immediately. Question 8. In C++, which keyword is used to define a function that does not return any value? A) void B) null C) return D) static Answer: A) void Explanation: The void keyword indicates that a function does not return any value.
D) int arr[;10]; Answer: A) int arr[10]; Explanation: The correct syntax for declaring an array of 10 integers is int arr[10];. Question 11. What is the primary purpose of a string in C, and how is it typically represented? A) A sequence of characters stored as an array of chars ending with a null terminator B) A sequence of integers stored in contiguous memory C) A pointer to a character in memory D) A fixed-size array of characters with no termination Answer: A) A sequence of characters stored as an array of chars ending with a null terminator Explanation: Strings in C are represented as character arrays ending with '\0', which marks the end of the string.
Question 12. Which operator is used for pointer arithmetic in C? A) + B) * C) & D) - > Answer: A) + Explanation: The + operator is used to move pointers forward by a certain number of elements. Question 13. How do you dynamically allocate memory for an integer array of size 20 in C? A) int *ptr = malloc(20 * sizeof(int)); B) int *ptr = new int[20]; C) int *ptr = calloc(20, sizeof(int)); D) Both A and C in C Answer: D) Both A and C in C
B) Memory leaks C) Infinite loops D) Compilation errors Answer: B) Memory leaks Explanation: Not freeing memory allocated with malloc or new leads to memory leaks, which waste resources. Question 16. Which C structure allows grouping different data types under one name? A) Class B) Array C) Structure D) Union Answer: C) Structure Explanation: Structures in C group variables of different types into one entity.
Question 17. In C++, which access specifier allows class members to be accessible from any function? A) private B) protected C) public D) hidden Answer: C) public Explanation: Members declared public are accessible from outside the class. Question 18. What is the purpose of constructors in C++ classes? A) To initialize objects when created B) To delete objects C) To define methods of a class D) To handle inheritance Answer: A) To initialize objects when created Explanation: Constructors automatically initialize objects when they are instantiated.
Explanation: Both #include "header.h" and #include <header.h> are valid; the difference is the lookup order. Question 21. Which file mode in file I/O in C++ is used to read and write in binary mode? A) "r" B) "w" C) "rb" or "wb" D) "b" Answer: C) "rb" or "wb" Explanation: The "r" and "w" modes are for text; "rb" and "wb" specify binary mode. Question 22. Which data structure is best suited for representing hierarchical relationships such as organizational charts? A) Array
B) Linked List C) Tree D) Hash Table Answer: C) Tree Explanation: Trees naturally model hierarchical relationships with parent- child connections. Question 23. In a binary tree, what is the maximum number of children each node can have? A) 1 B) 2 C) 3 D) Unlimited Answer: B) 2 Explanation: By definition, each node in a binary tree has at most two children: left and right.
parent, right children are greater, and inorder traversal produces sorted order. Question 26. Which heap property is maintained in a min-heap? A) Parent >= children B) Parent <= children C) Parent == children D) No specific property Answer: B) Parent <= children Explanation: In a min-heap, each parent node is less than or equal to its children. Question 27. Which algorithm is used to build a minimum spanning tree in a weighted graph? A) Dijkstra’s Algorithm B) Prim’s Algorithm
C) Bellman-Ford Algorithm D) Kruskal’s Algorithm Answer: B) Prim’s Algorithm Explanation: Prim’s algorithm grows a minimum spanning tree by selecting the smallest edge connecting the tree to a new vertex. Question 28. Which graph traversal algorithm uses a queue data structure? A) Depth-First Search (DFS) B) Breadth-First Search (BFS) C) Dijkstra’s Algorithm D) Topological Sort Answer: B) Breadth-First Search (BFS) Explanation: BFS uses a queue to explore neighbors level by level. Question 29. In a hash table, a collision occurs when: A) Two keys hash to the same index
Question 31. Which time complexity corresponds to linear search in an unsorted array? A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: C) O(n) Explanation: In the worst case, linear search examines all elements, leading to O(n) complexity. Question 32. Which sorting algorithm divides the array into smaller parts, sorts them recursively, and then merges? A) Bubble sort B) Quick sort C) Merge sort D) Selection sort Answer: C) Merge sort
Explanation: Merge sort uses divide-and-conquer by dividing the array, sorting subarrays, then merging. Question 33. Which comparison-based sorting algorithm is generally fastest on average? A) Bubble sort B) Insertion sort C) Quick sort D) Selection sort Answer: C) Quick sort Explanation: Quicksort has an average time complexity of O(n log n) and is typically faster than other comparison sorts. Question 34. Which non-comparison sorting algorithm sorts by processing individual digits or keys? A) Bubble sort