Float pointer
All concepts are similar to the integer pointer. If you are directly reading this article, kindly go through the integer pointer topic before getting started with this. Data type is the only difference.
A float pointer only stores an address of a float variable.
Syntax
float *ptr;
Referencing and dereferencing of a float pointer
Example
#include<stdio.h> int main() { float var = 3.1415,*ptr; ptr = &var; //ptr references var printf("Address of var = %x\n",&var); printf("ptr is pointing to an address %x\n",ptr); /* use '*' operator to access the value stored at ptr, i.e. dereferencing ptr */ printf("Value stored at ptr = %f",*ptr); return 0; }
Output
For the sake of understanding better, let's assume the address of a variable var.
If we assume address of a variable var as 1024 then the output of the above program will be,
Address of var = 1024 ptr is pointing to an address 1024 Value stored at ptr = 3.141500
Animated Tutorial
double(data type) pointer
A double(data type) pointer only stores an address of a double variable.
Syntax
double *ptr;
Referencing and dereferencing of a double(data type) pointer
Example
#include<stdio.h> int main() { double var = 367.141557,*ptr; ptr = &var; //ptr references var printf("Address of var = %x\n",&var); printf("ptr is pointing to an address %x\n",ptr); /* use '*' operator to access the value stored at ptr, i.e. dereferencing ptr */ printf("Value stored at ptr = %lf",*ptr); return 0; }
Output
If we assume address of a variable var as 2048 then the output of the above program will be,
Address of var = 2048 ptr is pointing to an address 2048 Value stored at ptr = 367.141557