Question:medium

What are the risks of using pointers without proper care?

Show Hint

Think of pointers like keys to hotel rooms. A memory leak is like booking a room and then losing the key – the room remains occupied but unusable. A dangling pointer is like having a key to a room after you've already checked out – trying to use it can lead to unexpected and dangerous situations.
Updated On: Feb 18, 2026
  • Memory leaks and dangling pointers can lead to crashes and security vulnerabilities.
  • Pointers can be slow and inefficient compared to direct access methods.
  • Pointers are only useful for advanced programming tasks.
  • Pointers make code difficult to understand and maintain.
Show Solution

The Correct Option is A

Solution and Explanation

Step 1: Core Concept:
Pointers, a key feature in C/C++, enable direct memory access. However, this power demands careful management to avoid serious program errors and security vulnerabilities. The central question concerns the most critical risks.
Step 2: Risk Analysis:
Let's examine the options:
1. Memory leaks and dangling pointers: This represents the most significant risk. A memory leak arises when allocated memory on the heap becomes inaccessible, preventing deallocation. This results in memory consumption over time, potentially leading to program crashes.
A dangling pointer references deallocated memory. Accessing this memory leads to undefined behavior including corrupted data, crashes, or security exploits (e.g., use-after-free). These are direct, severe risks.
2. Pointers are slow and inefficient...: This statement is generally incorrect. Pointers often *enhance* performance by avoiding data copying and enabling efficient data traversal.
3. Pointers are only for advanced tasks: This is false. Pointers are fundamental for many basic and intermediate tasks, such as dynamic data structures (linked lists), passing objects to functions, and hardware interaction.
4. Pointers make code difficult to understand and maintain: While poor coding practices can lead to this, it's a matter of code quality, not a direct runtime risk like crashes or security breaches. The issues in option 1 are the root cause.
Step 3: Conclusion:
The primary risks of improper pointer use are memory leaks and dangling pointers, which cause unpredictable program behavior, crashes, and security vulnerabilities.
Was this answer helpful?
0


Questions Asked in CUET (PG) exam