Values & References5 / 16
Up next

Pass by value copies

#include <print>
#include <vector>

// v is a full copy; changing it cannot affect the caller
void clear_copy(std::vector<int> v) {
    v.clear();
}

int main() {
    std::vector<int> nums{1, 2, 3};
    clear_copy(nums);
    // still 3: the function mutated its own copy
    std::println("{}", nums.size());
}
What you're solving

the callee gets its own copy