取消引用指针

pra*_*eep 3 c pointers

当我在fill函数中打包结构并传递指针以发送如何取消引用它时,如何取消引用指针?因为我在我所做的事情中得到了分段错误

#include<stdio.h>
struct xxx
{
    int x;
    int y;
};

void fill(struct xxx *create)
{
    create->x = 10;
    create->y = 20;
    send(*create);
}


main()
{
    struct xxx create;
    fill(&create);
}

send(struct xxx *ptr)
{
    printf("%d\n",ptr->x);
    printf("%d\n", ptr->y);
}
Run Code Online (Sandbox Code Playgroud)

Eva*_*ski 10

send(*create) 将发送实际的struct对象,而不是指针.

send(create) 将发送指针,这是你需要的.

当函数声明的参数包含星号(*)时,需要指向某事物的指针.然后,当您将该参数传递给另一个需要另一个指针的函数时,您需要传递参数的名称,因为它已经是一个指针.

使用星号时,您取消引用指针.这实际上发送了" create指向的内存单元格",实际的结构而不是指针.