Pointer variables, like all other variables, must be declared before they may be used in a C program. The interpretation of a pointer declaration differs, however, from the interpretation of other variable declarations. When a pointer variable is declared, the variable name must be preceded by an asterisk (*). The data type that appears in the declaration refers to the object of the pointer,i.e., the data item that is stored in the address represented by the pointer, rather than the pointer itself.
Thus, a pointer declaration may be written in general terms as
data-type *ptvar;
where ptvar is the name of the pointer variable, and data-type refers to the data type of the pointer's object. Remember that an asterisk must precede ptvar.
A C program contains the following declarations.
float u, v;
float *pv;
The first line declares u and v to be floating-point variables. The second line declares pv to be a pointer variable whose object is a floating-point quantity;i.e., pv points to floating-point quantity. Note that pv represents an address, not a floating-point quantity.
Monday, December 28, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment