Declaring Pointer Variables


A pointer variable is declared in the same way as that of normal variable except that the name of the pointer variable must be preceded by asterik(*). The syntax for declaring the pointer variable is :




Where :
  • data_type represents the  data type to which the pointer variable ptr_var_name will be pointing to. It may be of basic data type (int, char, float etc.) or user-defined data types (structure, union etc.)
  • The variable ptr_var_name follows the same rule as that of normal variable.
  • The asterisk(*) is the indirection operator that informs the compiler that the pat_var_name is not a normal variable instead it is a pointer variable.

The above declaration states that ptr is a pointer variable which can store the address of
any variable having data type int. It cannot point to any other type of variable. Some valid declarations are:

Declaration                            Meaning
Float *ptr;                               pointer variable ptr which can point to float type variable.
Char *ch;                                 pointer variable ch which can point to char type variable.
Double *p1;                            pointer variable p1 which can point to double type variable.


Previous                                                                                    Next


Powered by Blogger.