C++ Interview Questions (For 6+ Years Experience)
Part 1: Core C++ and OOP (12 Questions)
1. Difference between struct and class in C++?
2. What are virtual functions and how is a vtable constructed?
3. Why should destructors be virtual in base classes?
4. How does function overloading differ from function overriding?
5. Explain Liskov Substitution Principle with example.
6. What is dynamic polymorphism? When would you prefer static polymorphism?
7. What is object slicing?
8. Explain diamond problem and how C++ solves it.
9. What is the Rule of Three/Five/Zero?
10. When to use mutable keyword?
11. Difference between const, constexpr, and volatile?
12. How are exceptions handled internally in C++?
Part 2: C++11/14/17/20 Features (10 Questions)
13. What are smart pointers? Compare unique_ptr, shared_ptr, and weak_ptr.
14. What is move semantics? How does it improve performance?
15. Explain std::move vs std::forward.
16. What is a lambda function? Where would you use one?
17. Explain the use of auto and type inference in templates.
18. What is a perfect forwarding?
19. What is a constexpr function? When is it useful?
20. What is std::async and how does it differ from std::thread?
21. Explain range-based for loops and structured bindings (C++17).
22. What is std::optional and where should it be used?
Part 3: Data Structures & Algorithms (10 Questions)
23. Write code to reverse a linked list.
24. Explain difference between BFS and DFS (with use case).
25. Implement LRU Cache using STL.
26. Find first non-repeating character in a string.
27. Detect a loop in a linked list.
28. Implement producer-consumer problem using condition variables.
29. Sort an array of 0s, 1s and 2s.
30. Find the kth smallest element in an unsorted array.
31. Design a thread-safe bounded queue.
32. Explain STL containers: vector vs deque vs list.
Part 4: Multithreading & Concurrency (8 Questions)
33. What is race condition? How to avoid it in C++?
34. Explain std::mutex, std::lock_guard, and std::unique_lock.
35. What are deadlocks? How can they be prevented?
36. Difference between notify_one vs notify_all?
37. What is false sharing and how to avoid it?
38. Explain thread affinity and cache locality.
39. What is thread-safe singleton in C++?
40. Explain memory consistency models in multithreaded programs.
Part 5: System & Memory (6 Questions)
41. Explain memory layout of a C++ program.
42. Difference between heap and stack memory.
43. What causes segmentation fault?
44. How to detect memory leak in C++? (Tools: Valgrind, ASAN)
45. Explain shallow vs deep copy with code.
46. How is memory allocated for polymorphic classes?
Part 6: Project + Telecom/Practical (4 Questions)
47. Tell me about a multithreaded system you designed (telecom, SIP, etc.).
48. How did you optimize a real-time system for latency?
49. How do you handle memory and CPU constraints in embedded or telecom?
50. What is your approach to debugging a live production crash?