C++ functions and references

A reference parameter binds to the supplied object. Assignment through the reference updates that object, while a value parameter gives the function an independent copy.

C++
#include <iostream>
#include <cassert>
void add_bonus(int& score, int bonus) {
    score += bonus;
}
int main() {
    int score = 80;
    add_bonus(score, 5);
    std::cout << score << '\n';
    assert(score == 85);
}
Read the full lesson