C語言多級指針的使用
話不多說,直接代碼,以下是多級指針,通過指針變量修改變量的值
#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;
}
一定要注意:指針變量是用來存儲變量的指針,不能存值,以下例如:
int *p = 10;
這種寫法在C語言中是不合法的,因為指針變量p是存變量的指針,不能存儲常量值