How to Declare Pointer | Declaring Pointer in C Programming ?

January 7, 2012 No Comments » Hits : 210





How to Declare Pointer in C Programming ?


Syntax of Pointer 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

Valid Writing Styles : * can appears anywhere between Pointer_name and Data Type

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;

Incoming search terms: