Turning Learners Into Developers
Codekilla
CODEKILLA
back to course
Lesson 70 / 7199%· free preview
Exam Prep1/2

C++ Viva Questions

Rapid-fire viva questions (oral examination) covering every C++ topic — concise answers ready for face-to-face defence.

How to use this lesson

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.

Core Language

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 "...".

OOP

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.

Memory

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].

STL

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.

Modern C++

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.

Pro Tips for the Viva
  1. Answer in two sentences — examiners want crispness, not lectures.
  2. If you don't know, say "I'm not sure" + offer the closest concept you do know.
  3. Always end with a tiny example if time allows: "for example, std::vector<int> …".
  4. Keep eye contact, breathe, and never over-volunteer information.
AI-powered recap

Quick recap quiz?

We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.

# program

Program

C++
#include <iostream>
int main() {
    std::cout << "Codekilla viva — quick recap printer.\n";
    return 0;
}
Ready to move on?
// example library
Want more hands-on snippets in C++?
Browse 100 runnable examples · across 10 chapters · short, copy-paste-friendly · grouped by topic
Explore examples
// deep-dive
Go deeper — hand-picked articles
Long-form guides, shortcuts, and mental models that won't fit in a single lesson.
Open Blog
// feedback.matters()
Did this lesson help you?