A pointer is a variable in C, and the pointer's value is the address of a memory location. In this tutorial, you will learn about C Pointers, how it works in the C language and how you can use them in your C program.



Pointer Definition in C

Syntax:

type *variable_name;

Example:

int  *width;
char  *letter;

Benefits of using Pointers in C

  • Pointers allow the passing of arrays and strings to function more efficiently.
  • Pointers make it possible to return more than one value from the function.
  • Pointers reduce the length and complexity of a program.
  • Pointers increase the processing speed.
  • Pointers save the memory.

How to Use Pointers in C

Example:

#include<stdio.h>

int main ()
{
   int  n = 20, *pntr;  //actual and pointer variable declaration

   pntr = &n;  //store address of n in pointer variable

   printf("Address of n variable: %x\n", &n  );

   //address stored in pointer variable
   printf("Address stored in pntr variable: %x\n", pntr );

   //access the value using the pointer
   printf("Value of *pntr variable: %d\n", *pntr );

   return 0;
}

Output:

Address of n variable: 2cb60f04

Address stored in pntr variable: 2cb60f04

Value of *pntr variable: 20


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram