## February 19, 2011

### Basic Example to Understand Pointers

This is basic example i created to understand Pointers

code:

/*www.mycfiles.com
Basic Example to Understand Pointer's*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a=20,*p,**k;
clrscr();
p=&a;
k=&p;  /* here *p is pointer of a & **k of *p */
printf("\n1.Value of a=%d",a);
printf("\n\n3.Value of p=%u",p);
printf("\n\n4.Value of a=%d",*p);
printf("\n\n6.Value of k=%u",k);
getch();
}

Output:

Code Analysis:

Here we took 1 variable a whose value is 20
*p is a pointer of a & **k is pointer of *p

Put this in mind
Value of a=20

On line 1 We are printing value of a which is 20

On line 2 we are printing memory address of a which is 65524

On line 3 we are printing value of pointer p(*p) which is memory address of a is 65524. Coz p is pointer of a hence it is pointed to a

On line 4 we are printing value of a but with help of pointer p, so we are printing value present at pointer p(*p). *p=address of a.

On line 5 we are printing address of pointer p which is 65522

On line 6 we are printing value of k which is again address of pointer p(*p)

Hope you liked the posts, give comments if you have any doubts.. :)

### Related Posts :

Categories: , 