The typedef may be used in declaration of a number of pointers of the same type. It does not change the type, it only creates a synonym, i.e., another name for the same type as illustrated below.
typedef float* FP; // Now FP represents float*
float x,y,z;
FP px =&x, py = &y, pz = &z ; // Use of FP
In the above code px, py, and pz are pointers initialized with addresses of x, y, and z respectively.
Illustrates use of typedef in pointer declaration.
#include <stdio.h> void main() { typedef double* Dp; double x = 10.5,y = 8.6, z = 12.5; Dp px = &x , py = &y, pz = &z; clrscr(); printf("x = %.3lf,\t *px = %.3lf\t px = %p \n", x, *px, px); printf("y = %.3lf,\t *py = %.3lf\t py = %p \n", y, *py, py); printf("z = %.3lf,\t *pz = %.3lf\t pz = %p \n", z, *pz, pz); }
The expected output is as given below.