A collection of C++ questions with answers and code examples.
- 3. Difference between class and struct in C++? What is the difference between struct in C and in C++?
- 11. What Is a Default Constructor?
- 12. Can constructors be virtual? Why/why not?
- 13. What is a destructor, and when is it called?
- 14. What is a copy constructor? When is it called?
- 16. What are friend functions and friend classes?
- 17. What is the
thispointer? - 22. Explain const correctness (const int*, int* const, const methods).
- 25. Can we overload the
main()function? - 30. What are namespaces in C++? Why do we use them?
- 7. Explain Rule of 3, Rule of 5, Rule of 0.
- 9. Difference between lvalue and rvalue?
- 15. What is a dangling pointer?
- 20. What is object slicing?
- 21. What is multiple inheritance? What are the problems with it?
- 22. What is the diamond problem?
- 23. Explain virtual inheritance.
- 36. What is RAII? Why is it important in C++?
🖥️ Windows – MSVC (Visual Studio 2022) - cmake --preset windows-msvc-debug
🖥️ Windows – MinGW (GCC, Debug) - cmake --preset windows-mingw-gcc-debug
🖥️ Windows – MinGW (Clang, Debug) - cmake --preset windows-mingw-clang-debug
🐧 Linux – GCC (Ninja, Debug) - cmake --preset linux-gcc-debug
🐧 Linux – Clang (Ninja, Debug) - cmake --preset linux-clang-debug
🖥️ Windows – MSVC - cmake --build --preset windows-msvc-debug --parallel
🖥️ Windows – MinGW (GCC) - cmake --build --preset windows-mingw-gcc-debug --parallel
🖥️ Windows – MinGW (Clang) - cmake --build --preset windows-mingw-clang-debug --parallel
🐧 Linux – GCC - cmake --build --preset linux-gcc-debug --parallel
🐧 Linux – Clang - cmake --build --preset linux-clang-debug --parallel