Color theme
0 day streak0 XPP1
C++Learn mode
MISSION 1 OF 1

Tune through an alias

0 XP earned
C++ track: MasterMission: IntermediateReferencesAliasingMutation
Before you start this master track

Typed functions and collections. Be ready to reason about references, aliasing, and iterators.

Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.

x
0 / 2 challenges
LEARN THE CONCEPT

Understand it, then try it.

A reference gives an existing object another name. The ampersand in this declaration makes tuning refer to hertz instead of copying its initial value. Assigning through tuning therefore changes hertz. Both names observe the same integer, which is useful when a function or another scope must update an original value.

mission.cpp
#include <iostream>int main() {  int hertz = 432;  int& tuning = hertz;  tuning = 440;  std::cout << hertz << " / " << tuning << '\n';}

Each example is a complete C++17 console program with its own main function and required standard-library headers. Compile and run one mission at a time.

Track the values line by line. Predict the result before running this example in your own editor.