Lefora Free Forum
login join
Loading
369 views

What does the ampersand mean

Page 1
1–2
novice - member
27 posts

What purpose does the ampersand serve when it is put in front of a variable?

?
288 posts

& (ampersand) gives you the address of the variable (instead of the value).  For example:

int i = 22 ;
int* ptr = &i ;
cout << "catch " << i << endl ; // no pointer magic necessary
cout << "catch " << *ptr << endl ; // using pointer magic

Notice the * operator, which is the conjugate of *, it says "give me the value at the address".

& is usually called the "address operator"
* is usually called the "dereference operator"

__________________
Page 1
1–2

Locked Topic


You must be a member to post in this forum

Join Now!