dereferencing pointer in c

dereferencing pointer in c

Now till we have learn lot of programming and in all the programs. we have first declare variables in program and then used the name of variable for accessing it. But we can also access any variable indirectly using pointers. for accessing variable indirectly we will use indirection operator(*). it use by placing the indirection operator before the pointer variable. we can access any variable whose address is store in the pointer. Let us take example to understand

int a=90;
float b=87.6;
int *iptr=&a;
float *fptr=&b;

In this above example, if we place * before the iptr then we can access variable whose address is stored in the iptr, so iptr is contain the address of variable a, so we can access the variable a using *iptr. And in the same way we can access variable b using *fptr, so we can use *iptr and *fptr in place of variables name a and b every where in program. let us take some examples to understand this

*iptr is equivalent to a=9
(*iptr)– is equivalent a–;
x=*iptr+8; is equivalent to x=a+b;
printf(“%d %f”,*iptr,*fptr); is equivalent to printf(“%d %f”,a,b);

/* Dereferencing pointer variables */
#include<stdio.h>
int
main()
{
int i=67;

float f=89.7;
int *iptr=&i;
float *fptr=&f;
printf("value of iptr=Address of i=%p \n",iptr);
printf("value of fptr=Address of f=%p \n",fptr);
printf("Address of fptr=%p \n", &fptr);
printf("Address of iptr=%p \n", &iptr);
printf("value of i=%d %d %d \n",i,*iptr,*(&i));
printf("value of f=%d %d %d\n",f,*fptr,*(&f));
return 0;
}