简体   繁体   English

**pointer 和 &pointer 作为函数参数有什么区别?

[英]What is the difference between **pointer and &pointer as function parameter?

#include <stdio.h>

void initialize(int **);
void control(int **);

int main(void){

    int *pointer;
    printf("%p\n",pointer);
    initialize(&pointer);
    printf("%p\n",pointer);
    control(&pointer);

    return 0;
}

void initialize(int **point){
    printf("%p\n",point);
    *point = NULL;
    printf("%p\n",point);
}
void control(int **point){
    if(*point == NULL)
        printf("hi");
    else
        printf("good bye");
}

There is no problem in the code above, but when I change it like this:上面的代码没有问题,但是当我这样改的时候:

int **pointer;
printf("%p\n",pointer);
initialize(pointer);
printf("%p\n",pointer);
control(pointer);

It doesn't work properly.它不能正常工作。 I wonder why it doesn't work same as &pointer .我想知道为什么它与&pointer 不同

我试过你的代码,它给出了分段错误,这应该是由空指针引起的,当空指针的指针在 initialize() 函数中被赋值为 null 时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 指针和指针之间有什么区别 - What is the difference between pointer to pointer and a pointer 指向数组的指针和指向指针的指针有什么区别? - What is the difference between pointer to array and pointer to pointer? 在函数参数列表中声明char指针和char数组有什么区别? - What is the difference between declaring an char pointer and an array of chars in a function parameter list? 这两种声明指针的方式有什么区别? - What is the difference between these 2 ways of declaring a pointer to pointer? 指向缓冲区的指针和指向文件的指针有什么区别? - What is the difference between a pointer to a buffer and a pointer to a file? 指针和指针变量之间有什么区别? - What's the difference between a pointer, and a pointer variable? 指针地址和双指针地址有什么区别 - What is the difference between address of pointer and double pointer C中函数参数中的固定数组或指针之间的区别? - Difference between fixed array or pointer in a function parameter in C? function参数声明中const指针和const数组类型的区别 - Difference between const pointer and const array type in function parameter declaration 定义函数类型和函数指针类型有什么区别? - What is the difference between defining a function type and a function pointer type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM