double pointers in c programming language

Pointer which is pointing to double types of data is known as double pointers in c programming language. Example:

double *p;

Here p is double pointer.
A double pointer can hold the address of double type variables. Example:

double a=25.0;
double *p;
p=&a;

Properties of double pointer:

(1) If we well increment double pointer then address of double pointer will increment by 8 i.e. size of double data type. Example:

void main(){
double *ptr=100;
int i;
for(i=0;i<=3;i++)
printf("%d\n",ptr++);
}

Output:
100
108
116
124

(2) In the following declaration:

double **p;

Here variable p is not double pointer while variable *p is double pointer. Variable p is pointer to address of double variable not pointer to double variable. Example:

void main(){
double ***p;
double d=4.5;
**p=&d;
printf("%lf",***p);
}

Output:
4.500000

(3) We can pass the double pointer as a function parameter. Example:

double call(double *);
void main(){
double *p;
double x,y=.002;
p=&y;
x=call(p);
printf("%lf",x);
}
double call(double *q){
static double z=.003;
z=z**q;
return z;
}
Output:
0.000006

(4)When we will pass the double pointer in function it is also called as pass by reference. Hence any modification of content of function parameter in the called function will be also reflected in the actual variable which has passed in the calling function.
Example:

void call(double *);
void main(){
double da=.66;
double *p=&da;
call(p);
printf("%lf",*p);
}
void call(double *q){
*q=*q+5;
}

Output:
5.660000

(5) A function can also return double pointer.
Example:

double* call();
void main(){
double *p;
p=call();
printf("%.2lf",*p);
}
double * call(){
double *p;
static double i=23;
p=&i;
return p;
}

Output:
23.00

(6)

double* p,q;

In the above declaration p is double pointer while q is only double variable not the double pointer.

(7)

typedef double * Pointer;
Pointer p,q;

In the above declaration both p and q both are double pointer.

(8) Size of double pointer is two byte. (Since default pointer is near)
Post a Comment