What does this print?
int a = 1;int& r = a;r = 5;cout << a;
What this C++ test measures, in short
This test checks whether you can predict what real C++ does: when constructors and destructors run, how references and pointers alias, which function a virtual call reaches, what a move leaves behind, and how templates and the STL behave.
Snippets assume C++17 or later with <iostream> and using namespace std. Questions avoid undefined behaviour so each has one correct answer. They're our own and not standardised, so treat the result as a knowledge check, not a certification.
By What's Your IQ · Reviewed 4 Oct 2026- Format
- 15 predict-the-output questions, 4 options each
- Topics
- Basics and references, object lifetime, classes and virtual, move semantics, templates and STL
- Standard
- C++17, with a few C++20 notes
- Language
- Created by Bjarne Stroustrup at Bell Labs, from 1979
The stack cleans up after you
Objects on the stack are destroyed in reverse order when their scope ends, even if an exception is thrown. Tie a resource to an object and it can't leak. That idea is RAII.
Same job, fewer ways to get it wrong
Widget* w = new Widget();if (!w->init()) { return false; // leak!}use(w);delete w;auto w = make_unique<Widget>();if (!w->init()) { return false; // freed}use(*w);Every early return or exception between new and delete is a leak. unique_ptr deletes automatically when it goes out of scope.
- Stroustrup, B. (1994). The design and evolution of C++. Addison-Wesley.
- ISO/IEC JTC1/SC22/WG21. Standard C++ status and schedule. isocpp.org.
- Stroustrup, B. (2013). The C++ programming language (4th ed.). Addison-Wesley.