Introduction
Pointers are used to hold the addresses of the variables.
Above diagram illustrates the working of pointers. There is
one variable called no1. We have declared pointer ptr1. ptr1 is storing the
address of no1.
Declaration of normal variable and pointer variable.
int no1=11 ;
int *ptr1;
To store the address of variable no1, we have used below
syntax.
ptr1 = &no1;
To get the value pointed by ptr1, we can use below syntax.
X = *ptr1;
Simple pointer Example
#include<stdio.h>
void main()
{
int no=0;
int *ptr;
system("cls");
printf("\n Enter
number:");
scanf("%d",&no);
ptr=&no;
printf("\n %d is
stored at %u",no,ptr);
getchar();
}
No comments:
Post a Comment
Leave your valuable feedback. Your thoughts do matter to us.