九州编程
如果您想在C中修改函数中变量的内容,指针也是一个变量,您必须传递它。指针或间接参考总是用&地址和*去引用操作符。我是说*在更改变量的值时,始终使用运算符并将其放在前面。#include <stdio.h>#include <stdlib.h>void changeIntVal(int *x) {
*x = 5;}void changePointerAddr(int **q) {
int *newad;
*q = newad;}void changePPAddr(int ***q) {
int **dummy;
*q = dummy;}int main() {
int *p;
int **pp;
int *tempForPP;
int a = 0;
printf("\n The address pointing by p -> %p, pp -> %p, value of a -> %d ", p, pp, a);
p = &a;
pp = &tempForPP;
printf("\n The address pointing by p -> %p, pp -> %p, value of a -> %d ", p, pp, a);
changeIntVal(&a); // ----
// |---
changePointerAddr(&p); // ---- |----> parts of what I mean
// |---
changePPAddr(&pp); // ----
printf("\n The address pointing by p -> %p, pp -> %p, value of a -> %d ", p, pp, a);
return 0;}