一、二级指针也叫二重指针,实际应用中常用作函数参数,通过使用双指针改变实参的值,这里我在分析gpio-leds驱动的时候看到下面的代码,传入一维指针地址可以取出函数内部申请的动态内存,取出变量值。

二、实例测试
- #include
- #include
- #include "string.h"
-
- void Func(int** pp){
- int* p = malloc(sizeof(int));
- *p = 100;
- *pp = p;
- printf("&p=%p\tp=%p\t*p=%d\n",&p,p,*p);
- }
-
- void read_string( const char **propname){
-
- char * b = (char*)malloc(sizeof(char) * 10); //必须采用动态分配的方式
- strcpy(b,"heartbeat");
- *propname = b;
- }
-
- int main(){
- const char *state = NULL;
- int *p = NULL;
- Func(&p);
- printf("&p=%p\tp=%p\t*p=%d\n",&p,p,*p);
-
- read_string(&state);
- printf("state=%s\n",state);
-
- free(p);
-
- p = NULL;
- }

三、参考文章