C++ Interview Question

What is the difference between pass by value and pass by reference in C++?

Updated 2026-07-10 · Beginner friendly
Quick answer

Pass by value copies the argument into the function, so changes inside do not affect the original and copying can be costly for large objects. Pass by reference passes an alias to the original, so changes are visible outside and no copy is made. Use pass by value for small types, and pass by const reference for large objects you only read.

Pass by value

void addOne(int x) { x++; }   // change is lost, x was a copy

Pass by reference

void addOne(int& x) { x++; }  // change is visible to the caller

The performance angle

Copying a large object like a big vector by value is expensive. Passing by const reference avoids the copy while still preventing modification, which is the common pattern for read only large parameters.

In the interview

The rule interviewers want is small types by value, large types by const reference. Saying use a plain reference only when you intend to modify the caller's object rounds out a complete answer.

Want the full C++ guide?

Read every C++ concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the C++ guide All C++ questions