   C++ syntax (pointers etc)
  In learning how pointers work I made the following#include <iostream>using namespace std;int main (){  int number1 = 25;  int* pointer1 = &number1  int& address1 = *pointer1;    cout << number1 << " : number1" << endl;  cout << pointer1 << " : pointer1" << endl;  cout << address1 << " : address1" << endl;  cout << *pointer1 << " : *pointer1" << endl;  cout << &address1 << " : &address1" << endl;  cout << &number1 << " : &number1" << endl;  cout << &pointer1 << " : &pointer1" << endl;  number1 = 30;  cout << address1 << " : address1" << endl;  return 0;}The results I get show that int& address1 has the same address as number1 (that is, from my console I show (0012FF60 == &address1, 0012FF60 == &number1). So when I change the value of number1 to 30, it changes the value of address1 (address1 == 30).One thing that confuses me most is this line:int& address1 = *pointer1;The value of *pointer1 is 25.  How does address1 take on the address and value of number1 if I am assigning it the number 25?Anymore experiments I should try to help me learn?  Sorry if the names of the variables don't make sense, I was curious to see how an int& variable would work.Thanks.   
  Sounds like you need to read up on references. When you take a reference (by doing int& in your case) you are saying that address1 references what is pointed to by pointer1.So you can use address1 as if it were number1. When you change number1 what also references it shows the same change.You should read up on 'references' and 'passing by reference'. Also, i have seen a question regarding references and pointers in each job interview i had, so they are key to understandign and using C++.Hope that's enough for you to get going!   ;  The name address1 is misleading. Rename it to alias1 and it should become clear.   ;Quote:Original post by PrestoChungThe value of *pointer1 is 25.  How does address1 take on the address and value of number1 if I am assigning it the number 25?Note that *pointer1 gets you the actual variable at that memory address, not just the value.  That's why you can assign a reference to *pointer1, and that's also why you can do something like *pointer1 = 42; (which wouldn't make sense if *pointer1 just meant 25 because then you'd be doing 25 = 42;)   ;Quote:Original post by DevFredThe name address1 is misleading. Rename it to alias1 and it should become clear.Yup. See An alias (an alternate name) for an object also for further information.   ;  Thanks. I thought dereference operator just pointed to the value.  Sopointer1 == &*pointer1 == *&pointer1 == &*&*pointer1 == *&*&pointer1 ...*pointer1 == *&*pointer1 == *&*&*pointer1 ...&pointer1 == &*&pointer1 == &*&*&pointer1 ...Quote:Yup. See An alias (an alternate name) for an object also for further information.Do you have any links? I couldn't find much by searching.   ;Quote:Original post by PrestoChungpointer1 == &*pointer1Not exactly, because pointer1 = 0 is valid while &*pointer1 = 0 is not. *&var however is always the same as var.   