|
如题,二级指针作为函数的参数,函数里面怎么操作,才能修改二级指针指向的值呢?
一级指针时,函数中直接写:*p=多少,就可以了,如下
- #include <stdio.h>
- #include <stdlib.h>
- void test(int *p)
- {
- *p=100;
- }
- int main()
- {
- int a=1;
- printf("%d\n",a);
- test(&a);
- printf("%d\n",a);
- return 0;
- }
复制代码
但是二级指针时,怎么才能修改调用这p的指向呢?
- #include <stdio.h>
- #include <stdlib.h>
- struct obj
- {
- const int *pText;
- const int ItemNum;
- };
- const struct obj object={"0123456789",10};
- const struct obj *pobj=&object;
- void test(const struct obj **p)
- {
- *(*p)=&pobj; //这里怎么修改这个式子才能修改p的指向呢?????
- }
- int main()
- {
- const struct obj **p=NULL;
- test(p);
- printf("%s\n",*p->pText);
- return 0;
- }
复制代码
|
|