Pointers
C Pointers
A pointer is a variable in C, and pointers value is the address of a memory location.
Pointer Definition in C
Syntax:
type *variable_name;
Example:
int *width;
char *letter;
Benefits of using Pointers in C
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;
}
Address of n variable: 2cb60f04
Address stored in pntr variable: 2cb60f04
Value of *pntr variable: 20
Comments
Post a Comment