What is Pointer in C ?

  • For storing the address of another variable pointers can be used.
  • Variables of type int,char, array, function or any other pointer can be of type pointer.
  • Architecture of a pointer determines the size of the pointer.
  • Size of the pointer depends on the architecture.
  • In 32 bit the size of the pointer is 2 byte.
  • Using pointer some of programming tasks in C can be easily done.

Declaring a pointer

The pointer in c language can be declared using * (asterisk symbol). It is also known as indirection pointer used to dereference a pointer.

int *a; //pointer to int  
char *c;//pointer to char  

Pointer Example:

An example of using pointers to print the address and value is given below.

Pointer to array

int arr[10];  
int *p[10]=&arr; 

Pointer to a function

void show (int);  
void(*p)(int) = &display; 

 Pointer to Structure

struct st {  

   int i;  

    float f;  


struct st *p = &ref;  

Advantages of Pointer

  • Pointer reduces the code and improves the performance.
  • It is used to retrieving strings, trees, etc., and used with arrays, structures, and functions.
  • We can return multiple values from a function using the pointer.
  • It makes you able to access any memory location in the computer’s memory.

Usage of pointer

There are many applications of pointers in c language.

Dynamic memory allocation

  • In C language, we can dynamically allocate memory using malloc() and calloc() functions where the pointer is used.

Arrays, Functions, and Structures

  • Pointers in c language are widely used in arrays, functions, and structures.
  • It reduces the code and improves the performance.

Leave a Reply

Your email address will not be published.

You May Also Like