C pointer declaration



In the previous chapter we have learnt about Pointer operators supported by C Language. In this chapter we will be learning about declaration of Pointer Variable.

Syntax for Pointer Declaration in C :

data_type  *<pointer_name>;

Explanation :

data_type
  • Type of variable that the pointer points to
  •  OR data type whose address is stored in pointer_name
Asterisk(*)
  • Asterisk is called as Indirection Operator
  • It is also called as Value at address Operator
  • It Indicates Variable declared is of Pointer type
pointer_name
  • Must be any Valid C identifier
  • Must follow all Rules of Variable name declaration

Ways of Declaring Pointer Variable :

[box] * can appears anywhere between Pointer_name and Data Type[/box]

int *p;
int *        p;
int    *  p;

Example of Declaring Integer Pointer :

int n = 20;
int *ptr;

Example of Declaring Character Pointer :

char ch = 'A';
char *cptr;

Example of Declaring Float Pointer :

float fvar = 3.14;
float *fptr;

In the next chapter we will be learning Initialization of Pointer Variable in C Programming.