Declaration of Pointers in C++

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 (*). This identifies the fact that the variable is a pointer.

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.

This, the pointer declaration may be written in general terms as:

data-type *ptvar;

ptvar is the name of the pointer variable, and
data-type refers to the datatype of the pointer’s object.

Remember that an * (asterisk) must precede ptvar.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *