Use of multi-level pointers in C Language
In a few words, the direct code below is a multi-level pointer, using the pointer variable to modify the value of the Variable
# Include
# Include
Void secondPoint (int *** a, float *** f, double ***** d, char ****** c ){
** A = 100;
* ** F = 9.2f;
* *** D = 3.14;
* *** C = 'G ';
}
Int main (){
Int a0 = 10;
Int * a = & a0;
Float f0 = 0.1f;
Float * f1 = & f0;
Float ** f2 = & f1;
Double d0;
Double * d1 = & d0;
Double ** d2 = & d1;
Double *** d3 = & d2;
Char c0;
Char * c1 = & c0;
Char ** c2 = & c1;
Char *** c3 = & c2;
Char ***** c4 = & c3;
SecondPoint (& a, & f2, & d3, & c4 );
Printf (a = % d, f = %. 1f, d = %. 2lf, c = % c, a0, f0, d0, c0 );
System (pause );
Return 0;
}
Note: pointer variables are used to store pointers of variables and cannot store values. For example:
Int * p = 10;
This method is invalid in C, because the pointer Variable p is the pointer of the stored variable and the constant value cannot be stored.