Syntax

C++ Pass by Reference Syntax

In C++, pass by reference: lets a function modify the caller's variable — void inc(int& n) { ++n; }

Quick Answer

Syntax
void inc(int& n) { ++n; }
C++Syntax

Pass by Reference

Code example
void inc(int& n) { ++n; }

Lets a function modify the caller's variable.

Learn More

How to pass by reference in C++

  1. Open your C++ file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C++ Pass by Reference Syntax

Use void inc(int& n) { ++n; }.

Related Syntax References

Frequently asked questions

What is the C++ syntax for pass by reference?

Use this pattern: void inc(int& n) { ++n; }

Can I copy this C++ code example?

Yes. Use Copy code and adapt the example to your program.

Is this C++ syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify