C++ Basics and Syntax Interview Questions for C++
25 C++ Basics and Syntax questions with answers for c++ roles — 13 easy, 10 medium, 2 hard.
About C++ Basics and Syntax
Start with how a C++ program is compiled and linked, then learn data types, operators, control flow, functions, overloading, namespaces, const and static. This topic also covers undefined behaviour and common pitfalls that interviewers use to test whether you really understand the language rather than just its syntax.
What is the difference between a declaration and a definition?
Show answer
What are the fundamental data types in C++ and their typical sizes?
Show answer
What is the difference between ++i and i++?
Show answer
A teammate added using namespace std; to a shared header file. What problems can this cause?
Show answer
What are default arguments and what rules apply to them?
Show answer
What is the difference between struct and class in C++?
Show answer
Compare pass by value, pass by pointer and pass by reference.
Show answer
Write a function to reverse a string in place without using std::reverse.
Show answer
Write an efficient function to check whether a number is prime.
Show answer
Write a swap function using references and explain why a pass-by-value version fails.
Show answer
Why did you choose C++ for your career instead of a language like Python or Java?
Show answer
A program that prints a million lines with std::endl is very slow. Why, and how do you fix it?
Show answer
Explain the stages of compiling and running a C++ program.
Show answer
What is the difference between const and constexpr?
Show answer
What is function overloading and how does the compiler choose an overload?
Show answer
What does the static keyword mean in different contexts?
Show answer
What is the difference between an inline function and a macro?
Show answer
The linker reports undefined reference to a function that is declared in a header. What could be wrong?
Show answer
Two third-party libraries both define a global function called init and your build fails with duplicate symbols. How do you fix it?
Show answer
What are lvalues and rvalues?
Show answer
Write a C++ program that counts how often each word appears in the input.
Show answer
Tell me about a time you found a difficult bug in your C++ code.
Show answer
What is undefined behaviour in C++? Give examples.
Show answer
Your program gives correct output in a debug build but wrong output in a release build. How do you investigate?
Show answer
Frequently asked questions
How important is C++ Basics and Syntax in C++ interviews?
Start with how a C++ program is compiled and linked, then learn data types, operators, control flow, functions, overloading, namespaces, const and static. This topic also covers undefined behaviour and common pitfalls that interviewers use to test whether you really understand the language rather than just its syntax.
How should I use the C++ Basics and Syntax sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.