Next Generation Emulation banner

Difference between reference and pointers.

1330 Views 6 Replies 5 Participants Last post by  Syed Fawad
I tried to search the web but I am kinda having difficulty in finding some "basic" difference between these two in layman terms.


int A;
int *pA;
pA = &A;


int A;
int &rA = A;

So what?

A is the name of the address of 2 bytes reserved in memory for integer type.
pA is the pointer which contains the address of A.
So what would rA be?
1 - 1 of 7 Posts
In C++, references are implicit pointers. Basically, when passing a reference, the receiving function has only a copy of the value in the address passed. The value in the original function cannot be manipulated by anything but its originating function. So it's like a "safer" but less versatile pointer. If you want a detailed read on when to use which, try this.

In C, there are only pointers.

In Java, there are only references.
1 - 1 of 7 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.