"Hello World" is 11 bytes (including null terminator). Writing to 10-byte buffer causes buffer overflow, corrupting adjacent memory.
Q.14Hard
For implementing a dynamic stack in competitive programming, which memory management approach is best?
Answer: B
Single allocation with index tracking minimizes malloc/free overhead, suitable for competitive programming time constraints.
Q.15Hard
In a dynamic stack implementation for competitive programming, how should you handle reallocation when the stack becomes full?
Answer: A
Doubling capacity and using realloc() provides amortized O(1) insertion with manageable memory overhead, which is the standard approach for dynamic data structures.
Q.16Hard
Which of these represents proper error handling for malloc in competitive programming?
Answer: A
Checking if malloc returns NULL before using the pointer is essential error handling. If allocation fails, the program should handle it gracefully rather than proceeding with NULL.
Q.17Hard
For a dynamic hash table with chaining, if collision occurs, the new element should be inserted where?
Answer: D
While both work, inserting at beginning provides O(1) insertion; end requires traversal. Choice depends on use case.
Q.18Hard
What is the memory overhead when allocating 1000 integers vs 1 integer in a system with malloc metadata?
Answer: C
Each malloc() call has fixed metadata overhead (typically 8-16 bytes). Single allocation of 1000 ints has less overhead than 1000 separate allocations.
Q.19Hard
In competitive coding, when implementing dynamic trees, which traversal is most suitable for level-order?
Answer: C
Level-order traversal requires BFS which uses a queue. Dynamic queue allocation handles arbitrary tree sizes efficiently.
Q.20Hard
Which memory allocation technique provides better locality of reference for accessing array elements?
Answer: B
Contiguous allocation places array elements next to each other in memory, improving cache hits and CPU performance through spatial locality.