three way to use * and &
int* p; // 1. variable p is pointer to integer type
int i; // integer value
p = &i; // 2. pointer p will point to the integer i
i = *p; // 3. I will be filled with the value of p
words-words:
int
is type
p
and i
is variable
variable can value variable, or pointer variable
value variable store data
pointer variable store address
- asterisk on type. it means a pointer type. in the example above, it means pointer of integer-type. This is the only time you use * or & on type.
- ampersand on value variable. it means the address of that value.
- asterisk on pointer variable. it means dereference, returning the value of that pointer.