| C Tutorial | Pointers in C | |||
|
Data types in C
|
Pointers A pointer is a value which represents a reference to another value sometimes known as the pointer's "pointee". Hopefully you have learned about pointers somewhere else, since the preceding sentence is probably inadequate explanation. This discussion will concentrate on the syntax of pointers in C -- for a much more complete discussion of pointers and their use see http://cslibrary.stanford.edu/102/, Pointers and Memory.
Syntax Syntactically C uses the asterisk or "star" (*) to indicate a pointer. C defines pointer types based on the type pointee. A char* is type of pointer which refers to a single char. a struct fraction* is type of pointer which refers to a struct fraction.
int* intPtr; // declare an integer pointer variable intPtr
char* charPtr; // declares a character pointer -- // a very common type of pointer
// Declare two struct fraction pointers // (when declaring multiple variables on one line, the * // should go on the right with the variable) struct fraction *f1, *f2;
The Floating "*" In the syntax, the star is allowed to be anywhere between the base type and the variable name. Programmer's have their own conventions-- I generally stick the * on the left with the type. So the above declaration of intPtr could be written equivalently...
int *intPtr; // these are all the same int * intPtr; int* intPtr;
Want To Know more with
Video ???
|
|