Reference and reference parameters in C++: Examples and Limitations

A reference is an implicit pointer used to create functions to use parameter passing by call by reference.

For Example:

#include <iostream>

using namespace std;

void swap(int &a, int &b);

int main()


int x, y;

a = 5;

b = 9;

swap(a, b);

cout << “New x and y are ” << x << ” ” << y << “\n”;

return 0;


void swap(int &a, int &b)


int m;

m = a;

a = b;

b = m;



New x and y are 5 9

Limitations of reference:

1) Address of a reference can’t be obtained.

2) A pointer to a reference can’t be created.

3) Arrays of reference can’t be created.

4) A bit field can’t be referenced.

5) Null reference can’t be created.

6) A reference variable has to be initialized when its declared. Exceptions are when the variable is a member of a class, a return value or a function parameter.


Leave a Reply