Interview Q&A · C++ · 10 questions in this topic

C++ Fundamentals — C++ Interview Q&A

All C++ topics

The vocabulary every C++ interview opens with — what the language is, how source becomes an executable, namespaces, I/O and the basic type system. Part of C++ Fundamentals · 213 questions in the C++ bank.

What is C++?

Answer

C++ is a general-purpose, statically typed, compiled programming language that extends C with object-oriented programming, generic programming (templates) and a rich standard library. It gives low-level control over memory and performance while also supporting high-level abstractions with zero or minimal runtime overhead.

It was created by Bjarne Stroustrup (first released in 1985) and is standardized by ISO — C++11, C++14, C++17, C++20 and C++23 are the major modern revisions. Typical uses are systems software, game engines, browsers, databases, embedded systems and performance-critical backends.

Example

Example.cppcpp
#include <iostream>
int main() {
    std::cout << "Hello, interviewer!\n";
    return 0;
}

💡 Name one low-level strength (deterministic memory control, no garbage collector) and one high-level strength (classes, templates, STL) — that frames every follow-up answer.

How does a C++ program go from source code to a running program?

Answer

Roughly four stages: preprocessing (handles #include, #define, conditional compilation), compilation (each translation unit is compiled to object code), linking (object files plus libraries are combined into an executable), and loading/execution (the OS loader maps the executable into memory and starts main).

Most interview bugs live at a specific stage: a missing header is preprocessing, a type error is compilation, an undefined reference is linking, and a segfault is runtime.

Key points

  1. 1Preprocessing — expands #include files and macros into a translation unit.
  2. 2Compilation — each .cpp compiles independently to a .o object file.
  3. 3Linking — resolves symbols across object files and libraries into one binary.
  4. 4Loading — the OS loads the binary; execution starts at main().

Example

Example.cppcpp
// a.cpp
int add(int a, int b) { return a + b; }
// main.cpp
int add(int a, int b); // declaration
int main() { return add(2, 3); }
// build: g++ -c a.cpp; g++ -c main.cpp; g++ a.o main.o -o app

💡 Saying undefined reference is a linker error (not a compiler error) is a classic signal you have actually built multi-file C++ programs.

What happens when you run `int main()` and what can main return?

Answer

main is the program entry point. The hosted-environment signatures are int main() and int main(int argc, char* argv[]). Returning 0 (or falling off the end of main, which implicitly returns 0) means success; returning non-zero signals failure to the operating system.

argc is the argument count including the program name, and argv holds the argument strings with argv[argc] guaranteed to be nullptr.

Example

Example.cppcpp
#include <iostream>
int main(int argc, char* argv[]) {
    std::cout << "args: " << argc << "\n";
    for (int i = 0; i < argc; ++i)
        std::cout << argv[i] << "\n";
    return 0;
}

💡 Mention that falling off main returns 0 implicitly — it is the only function where that is legal, and interviewers sometimes probe it.

Recommended resourcesAffiliate links · may earn us a commission

Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits