Answer: In C every variable must be declared according to the type of value the variable stores. Since pointer variable contain addresses that belong to a seprate data type, they must be declared as pointers before we use them. The syntax of declaring pointer variable is:
The above declaration tells three things about the variable pt_var_name to the compiler.
int * ptr;
declares the variable ptr as a pointer variable that points to an integer data type.
The above declaration instructs the compiler to allocate memory location for pointer variable ptr. Since the pointer variables are not initialized, they point to some unknown location.
The process of assigning the address of a variable to a pointer variable is known as initialization. Once a pointer variable has been, declared we can use the assignment operator to initialize the variable.
ptr=∑ /* initialization*/
we can also combine the declaration and initialization in one statement:
The only requirement is that the variable sum must be declared before the initialization takes place.
At the time of initialization, we must ensure that the pointer variables always point to the corresponding type of data.