&Object1 or Object1&?

I have known the syntax &Object since I first learned C. Today I saw on a website a notion "Object&". The webpage seems to use it as the address to the Object. Is "Object&" equivalent to "&Object"?
Here is what I saw it:

http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr035.htm

I was going to build a class and store new object addresses in a static array. I was trying to use "this" in constructor to get the new object address to the static array, such as "all_Objects" and stumbled upon this above webpage.

Thanks.

This takes the address of foo:

int foo = 10;

int * bar = &foo;

Now you can change foo by dereferencing the pointer:

 *bar = 20;   // change foo using a pointer

This takes a reference to foo:

int & dolphin = foo;

Now you can change foo by using the reference (note there is no asterisk):

 dolphin = 42;  // change foo using a reference

Full demo code:

void setup ()
{
int foo = 10;
int * bar = &foo;    // pointer to foo
int & dolphin = foo;  // reference to foo

 Serial.begin (115200);
 Serial.println (foo);
 *bar = 20;   // change foo using a pointer
 Serial.println (foo);
 dolphin = 42;  // change foo using a reference
 Serial.println (foo);
}
void loop () {}

References are immutable. That is, now that dolphin "references" foo you can't make it reference anything else.

Thanks Nick! That makes all the sense now. So will bar and bar2 be equivalent? :cold_sweat:

int foo=10;
const int * bar=&foo;
int & bar2=foo;

Well, one's a pointer and one's a reference. But they are "pointing" to the same thing.

Remember, you have to dereference bar (eg. *bar) but you don't dereference bar2. So no, they are not equivalent as such.

Got it! Thanks again!