首页 > 解决方案 > 传递对 C 中函数的引用

问题描述

我试图构建一个将引用作为参数的函数。

但是编译给了我一个错误警告,说是预期的')',我不知道是什么问题。
我们不能在 C 中使用引用作为参数吗?
以下是代码段。

typedef struct Qnode{
    struct Qnode* first;
    struct Qnode* rear;
    int value;
}Queue;

int init_Queue(Queue &q)  //expected')'  as the compiler warned me.
{
    return 1;
}

我应该使用指针而不是引用作为参数吗?

标签: cparametersreference

解决方案


C 没有引用。那是一个 C++ 结构。

您需要更改函数以接受指针。

int init_Queue(Queue *q)
{
    printf("value=%d\n", q->value);
    return 1;
}

推荐阅读