Referencing means taking the address of an existing variable (using &) to set a pointer variable. In order to be valid, a pointer has to be set to the address of a variable of the same type as the pointer, without the asterisk:
int c1;
int* p1;
c1 = 5;
p1 = &c1;
//p1 references c1
Dereferencing a pointer means using the *operator (asterisk character) to access the value stored at a pointer. NOTE: The value stored at the address of the pointer must be a value of the same type as the type of variable the pointer "points" to. e.g. *p = *p +1; Note: & is the reference operator and can be read as “address of”. * is the dereference operator and can be read as “value pointed by”. |
No comments:
Post a Comment