Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Call by Value vs Call by Reference

1 topic · 28 Nov 2026
1

Call by Value vs Call by Reference ★★★★★

C++

Call by value passes a copy, so changes inside the function do not affect the caller. Call by reference passes the variable itself.

C++
void byValue(int a)      { a = 100; }
void byReference(int &a) { a = 100; }
void byPointer(int *a)   { *a = 100; }

int main() {
    int x = 1;
    byValue(x);      cout << x;  // 1   (copy changed)
    byReference(x);  cout << x;  // 100
    x = 1;
    byPointer(&x);   cout << x;  // 100
}

Tip: pass large objects as const T& to avoid copying and to stop accidental changes.