twitter
    Find out what I'm doing, Follow Me :)

How Do You Declare A Pointer?

Now to keep a promise and tell you how to declare a pointer. Refer to the third line of the program and you will see our old familiar way of defining the variable "index", followed by two more definitions. The second definition can be read as "the storage location to which "pt1" points will be an int type variable". Therefore, "pt1" is a pointer to an int type variable. Likewise, "pt2" is another pointer to an int type variable.

A pointer must be defined to point to some type of variable. Following a proper definition, it cannot be used to point to any other type of variable or it will result in a "type incompatibility" error. In the same manner that a "float" type of variable cannot be added to an "int" type variable, a pointer to a "float" variable cannot be used to point to an integer variable.


Compile and run this program and observe that there is only one variable and the single statement
in line 9 changes the one variable which is displayed three times.