Pointers are variables that have as their value an address, i.e. a reference to another data object. Given a pointer we can access the value "pointed" to through a process known as dereferencing.
* (Asterisk) & (Ampersand)
int *numberPtr;
*numberPtr = *numberPtr + 1;
numberPtr = &xIn this case x is referred to as a reference variable.
Consider the following example:
#includevoid main(void) { int n, *nptr; scanf("%d",&n); nptr = &n; printf("Value of n = %d\n",n); printf("Address of n = %d\n",&n); printf("Value of nptr = %d\n",nptr); printf("Address of nptr = %d\n",&nptr); printf("Value pointed at by nptr = %d\n",*nptr); }
Note that the address of n and the value of nptr are the same.
with CS_IO; use CS_IO; procedure ACCESS is type INTEGERPTR is access integer; INT_PTR: INTEGERPTR:= new integer'(2); begin put(INT_PTR.ALL); new_line; end ACCESS;Note that the variable INT_PTR is referred to as an access variable.
Created and maintained by Frans Coenen. Last updated Wednesday July 3 1996.