✅ Coding Interview Questions with Answers Part-4 🧠💻
31. What is a pointer
A pointer stores the memory address of a variable.
- Direct memory access
- Efficient data handling
Used in C/C++, dynamic memory allocation.
32. Difference between pointer and reference
Pointer: holds address, can be null, can change target.
Reference: alias of variable, cannot be null, cannot change binding.
Pointer is flexible, reference is safer.
33. What is a memory leak
Memory leak: memory not released.
- Program slows down
- App crashes
Causes: missing free/delete, unclosed resources.
Use garbage collection or smart pointers.
34. What is segmentation fault
Segmentation fault: invalid memory access.
- Access null pointer
- Array index overflow
Seen in C/C++. Check pointer usage.
35. Difference between process and thread
Process: independent, own memory, heavier.
Thread: part of process, shared memory, lightweight.
Threads share resources.
36. What is multithreading
Multithreading: runs tasks in parallel.
- Better CPU use
- Faster execution
Examples: web servers, background tasks.
Risk: data inconsistency.
37. What is synchronization
Synchronization: controls shared data access.
Prevents race conditions. Use locks, mutex, semaphores.
Safety over speed.
38. What is deadlock
Deadlock: threads wait forever.
- Thread A holds lock 1
- Thread B holds lock 2
Result: system freeze.
39. Conditions for deadlock
All four must exist:
- Mutual exclusion
- Hold and wait
- No preemption
- Circular wait
Break one to avoid deadlock.
40. Shallow copy vs deep copy
Shallow: copies reference, changes affect both.
Deep: copies data, fully independent.
Example: objects with nested data.
Double Tap ♥️ For More
Post #2770
1.48K
- ❤ 1