* vs &

what's the difference between *(pointer) and &(reference)? sometime i see code use * and sometime it uses &, i'm comfuse as when to use which.
thanks.

They are the reverse of each other. The ampersand gives you an address of an object. The star uses an address stored in an object.

int i, *p;
i=5;   /* i is now 5 */
p=&i;  /* the address of i is now stored in p */
*p=6;  /* i is now 6 but p did not change */

& is also used in "pass by reference" in C++ (not C). Works like pointers but some people may consider easier to work with by reference instead of pointers:

#include <stdio.h>
void add(int &a, int b) {
   // adds a and b, and put result to
   // variable referenced by "a"
   a += b;
}
int main(int argc, char** argv) {
   int myval = 4;
   // myval references to "a" in add(), so a change
   // to either one modifies the same variable
   add(myval, 6);
   printf("%d\n", myval);    // should be 10
   return 0;
}

just a few pointers.. (;))

Unlike pointers, you must immediately initialize a reference:

Also remember that you can't use an operator to operate on the reference like you can do with pointers. An example...