C++ Viva Questions
Rapid-fire viva questions (oral examination) covering every C++ topic — concise answers ready for face-to-face defence.
This is a curated rapid-fire list — the kind your viva examiner will fire at you in 5–10 seconds each. Read each Q+A out loud once, then quiz yourself with the question alone.
Q1. What is C++? A. A general-purpose, statically-typed, compiled, multi-paradigm language created by Bjarne Stroustrup in 1979 as "C with classes".
Q2. Difference between C and C++? A. C is procedural; C++ adds OOP (classes, inheritance, polymorphism), templates, references, and exceptions.
Q3. What is a compiler?
A. A program that translates source code into machine code — g++, clang++, MSVC.
Q4. What's the role of main()?
A. The program's entry point. The OS calls main and uses its return code as the exit status.
Q5. What's a header file?
A. A file (.h / .hpp) holding declarations included via #include. Built-in headers use <...>; user headers use "...".
Q6. Define a class. A. A user-defined type bundling data members and member functions; instances are objects.
Q7. Four pillars of OOP? A. Encapsulation, Abstraction, Inheritance, Polymorphism.
Q8. Constructor vs destructor? A. Constructor runs at object creation to initialise; destructor runs at destruction to release resources.
Q9. What is a virtual function?
A. A member function declared virtual in the base class so derived overrides are dispatched at runtime via the vtable.
Q10. What is the diamond problem?
A. When a class inherits the same base via two paths — solved with virtual inheritance.
Q11. Difference between stack and heap?
A. Stack is fast, fixed-lifetime, function-scoped. Heap is manually managed (new/delete or smart pointers), arbitrary lifetime.
Q12. Why prefer smart pointers over raw new?
A. Automatic cleanup, exception safety, ownership semantics — unique_ptr, shared_ptr.
Q13. What is RAII? A. Resource Acquisition Is Initialization — bind resource lifetime to an object so destructors release them automatically.
Q14. What is a memory leak? A. Memory allocated on the heap that is never freed; over time the program consumes more RAM than needed.
Q15. delete vs delete[]?
A. delete for a single object; delete[] for arrays allocated with new T[n].
Q16. What is the STL? A. A library of generic containers, iterators, and algorithms.
Q17. Vector vs list? A. Vector is contiguous, random-access O(1), insert-end O(1) amortised. List is doubly-linked, insert/erase O(1) but no random access.
Q18. Map vs unordered_map? A. Map is sorted, O(log n). Unordered_map is hashed, O(1) average.
Q19. What is an iterator? A. A pointer-like object that walks through container elements; algorithms accept iterator pairs.
Q20. What does auto do?
A. Asks the compiler to deduce the variable's type from its initializer.
Q21. What is a lambda?
A. An anonymous function expression [capture](params){ body; } introduced in C++11.
Q22. What does nullptr solve?
A. Replaces ambiguous NULL (which was 0); is type-safe with pointer-only conversions.
Q23. What is std::move?
A. A cast to rvalue-reference enabling move semantics — transfers resources without copying.
Q24. const vs constexpr?
A. const = read-only at runtime. constexpr = evaluable at compile time.
Q25. What are templates? A. Generic blueprints that the compiler stamps out for each requested type.
- Answer in two sentences — examiners want crispness, not lectures.
- If you don't know, say "I'm not sure" + offer the closest concept you do know.
- Always end with a tiny example if time allows: "for example,
std::vector<int>…". - Keep eye contact, breathe, and never over-volunteer information.
Quick recap quiz?
We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.
Program
#include <iostream>
int main() {
std::cout << "Codekilla viva — quick recap printer.\n";
return 0;
}
