UMBC CMSC 201 Fall '05
CSEE | 201 | 201 F'05 | lectures | news | help
type *nameOfPointer; type *nameOfPointer = &aVariable;Examples:
int *iPointer; double *dPtr;Note -- the & operator, known as the address of operator is used to get the address of a variable, function, structure etc. It is NOT the reference operator.
It does not matter where you place the * operator i.e. the following are all acceptable.
double * ptrDble;
Pointers and non-pointers can be declared together:
double * ptrDble, aDouble;where ptrDble is a pointer to a double whereas aDouble is just a variable of type double.
As with all variables, you must initialize a pointer before you actually use it. Otherwise it can lead to unpredictable program behaviour. (i.e. Your program will normally core dump)
A: Because C provides operations on pointers (e.g., *, ++, etc) whose meaning depends on the type of thing pointed to.