C++
0Loading crowd target
0Loading crowd target
7correct to beat the crowd
50 free C++ trivia questions with answers — science & nature quiz, new questions added Oct 2026.
C++ runs an astonishing share of the software people touch every day: game engines, web browsers, databases, trading systems and the firmware inside cars and cameras. It is also a language with a reputation, admired for its speed and control and feared for the ways it lets a careless programmer go wrong. That mix makes it a rich subject for a quiz. The questions here start where a first course does, with the syntax every beginner meets in week one, then move through memory management, object-oriented features, generic code and the standard library. Mixed in is the history: where the language came from, how it got its name, the jokes its designer made at its expense and the nicknames programmers have given its stranger corners. It works as practice before a class test or a technical interview, and as a pub-quiz round for anyone who has ever stared at a page of compiler errors. Every answer comes with a short explanation, so a wrong guess still teaches you something.
30 of 50 questions with answers and explanations. Play the quiz
Q 01C++'s creator joked that C makes it easy to shoot yourself in the foot, but C++ blows off what?
Your whole leg
Your whole leg is the punchline: he said C++ makes the mistake harder to make but far worse when it happens. He confirms saying it around 1986, and adds that it is true to some extent of every powerful language.
Q 02Which Danish computer scientist began work in 1979 on the extension of C that grew into C++?
Bjarne Stroustrup
Bjarne Stroustrup wanted a language as efficient and flexible as C that also offered high-level features for organising large programs. Nearly two decades passed before it was first standardised, in 1998.
Q 03The '++' in the name C++ is which operator from C, signalling a step beyond the older language?
Increment
Increment is what ++ does in C: it adds one to a variable. As the language's creator likes to point out, the slightly shorter name "C+" is a syntax error.
Q 04At which research lab, also the birthplace of the transistor and Unix, was C++ first developed?
Bell Labs
Bell Labs, then the research arm of AT&T, is also credited with the laser, information theory and the C language on which C++ was built.
Q 05Which game engine from Epic Games, the technology behind Fortnite, is written in C++?
Unreal
Unreal Engine is written in C++, and Epic removed its home-grown UnrealScript language from version 4 so that game logic would be written in C++ as well.
Q 06Before it was renamed in 1983, what descriptive name did the language that became C++ go by?
C with Classes
C with Classes began as additions to a C compiler, among them derived classes, strong typing, inlining and default arguments. It was also briefly called C84 before the final name stuck.
Q 07Which punctuation mark, used the same way in C and C#, must end almost every statement in C++?
A semicolon
A semicolon is a terminator in the C family, required after every statement, whereas languages such as Python and Go can infer the end of a statement from the end of the line.
Q 08Which Sun Microsystems language kept a C++-style syntax to feel familiar, but dropped pointer arithmetic?
Java
Java was given a syntax that C and C++ programmers would recognise, but with fewer low-level facilities than either: object addresses cannot be manipulated by adding or subtracting an offset.
Q 09Which two characters start a single-line comment in C++, a style revived from the older BCPL?
//
// comments run to the end of the line. BCPL had them, C left them out in favour of /* */ blocks, and C++ brought them back, with C itself following in 1999.
Q 10Under the C++ standard, which type must main return, its value going back to the system?
int
int is the only return type the standard permits for main. C++'s creator notes that void main() has never been valid C++, and that falling off the end of main returns 0, meaning success.
Q 11Which standard header, stripped of its .h when C++ was standardised, provides the console input and output streams?
<iostream>
<iostream> defines the standard stream objects for input, output, errors and logging. Its name is short for input/output stream, and until the 1998 standard it was written <iostream.h>.
Q 12Which stream object, used with the << operator, writes text to a C++ program's standard output?
std::cout
std::cout is pronounced "see-out". The c stands for character, because the stream library converts values to and from their character representations.
Q 13Which directive, followed by a file name in angle brackets or quotes, pastes a header into C++ source?
#include
Q 21Which symbol, also C++'s bitwise NOT operator, is placed before a class's name to form its destructor?
A tilde
A tilde marks the destructor, which runs automatically at the end of an object's lifetime, so a class named X does its cleaning up in ~X().
Q 22Which object-oriented feature lets a C++ class take on the members of an existing base class and add its own?
Inheritance
Inheritance lets programmers reuse existing code and extend it. C++ is among the languages that go further, allowing one class to derive from several parents at once.
Q 23Which access level do members of a C++ struct get by default, unlike those of a type declared with class?
public
#include is replaced by the text of the named file before compilation proper. Angle brackets search the system directories, while double quotes look beside the including file first.
Q 14Which operator tests two C++ values for equality, a notorious source of bugs when confused with assignment?
==
== compares, while a single equals sign assigns. Because an assignment has a value in C and C++, writing if (x = y) still compiles, which is what makes the slip so hard to spot.
Q 15Which C++ operator gives the remainder of an integer division, and refuses floating-point operands?
%
% is the remainder operator, so 7 % 3 is 1. Both of its operands must be integers; for floating-point values the library function std::fmod does the same job.
Q 16Which keyword, shared by C and C++, marks a variable as read-only so the compiler rejects later assignments?
const
const turns a promise into something the compiler enforces. Careful C++ style, known as const-correctness, is to declare every variable that way unless it truly needs to change.
Q 17Which C++ iteration statement always executes its body at least once, testing its condition afterwards?
A do-while loop
A do-while loop is a post-test loop: the body runs first and the condition is checked only afterwards. The other forms test before the first pass, so their bodies may never run at all.
Q 18Which C++ keyword, the counterpart of 'next' in Perl and Ruby, skips the rest of the current loop iteration?
continue
continue jumps straight to the start of the following pass, whereas its partner break abandons the loop altogether.
Q 19Which C++ operator requests memory on the heap, builds an object there and returns its address?
new
new signals failure with a std::bad_alloc exception, so its result needs no checking. Each use must later be matched by delete, which hands the memory back to the free store.
Q 20Which special C++ member function shares its class's name, has no return type and runs when an object is created?
A constructor
A constructor has the task of initialising the object's data members. If a C++ class does not say how it should be copied, the compiler quietly generates a copying version of its own.
public is the default for a struct and private for a class. Otherwise a C++ struct is simply a class: it can have member functions and base types of its own.
Q 24Which symbol after a type name declares a C++ reference, an alias that can never be made to refer elsewhere?
An ampersand
An ampersand after the type makes a reference, which must be bound to an object when it is declared and cannot be null. An asterisk in the same spot would declare a pointer instead.
Q 25Which C++ operator reaches a member through a pointer, as shorthand for a dereference followed by a dot?
->
-> folds two steps into one: p->x means exactly (*p).x. Class types such as smart pointers can define their own version, which lets them be used just like raw pointers.
Q 26What is the C++ operator :: called, as used in std::string to say which library a name belongs to?
Scope resolution
Scope resolution is the official name for the double colon. In PHP the same symbol is also called Paamayim Nekudotayim, which is Hebrew for "double colon".
Q 27Which C++ feature groups identifiers under a prefix such as std, so two libraries can use the same one without clashing?
A namespace
A namespace keeps names apart, and the entire standard library lives in the one called std. Before standardisation, many of its components were simply global.
Q 28Which C++ keyword, a pointer for historical reasons, refers to the object a member function was called on?
this
this is a pointer only because it entered the language before references did. Its designer has said that it would otherwise have been a reference.
Q 29Which keyword gave C++ a type-safe way to say 'points at nothing', replacing a bare 0 or an old C macro?
nullptr
nullptr has a type of its own, so it converts to any pointer but not to an ordinary integer. The old macro was usually just 0, which could send a call to a function expecting a number.
Q 30Which C++ keyword, once an obscure storage specifier, now makes the compiler deduce a variable's type?
auto
auto takes a variable's type from its initialiser, fixed at compile time. It spares programmers from spelling out long template type names by hand.