简体   繁体   中英

Pass reference to a function in C

I tried to construct a function that has the reference as a parameter.

But the compile gave me a error warning, saying that expected')', I don't know what is the problem.
Can't we use reference as parameter in C?
The following is the code segment.

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;
}

Should I use a pointer instead of a reference as a parameter??

C doesn't have references. That's a C++ construct.

You'll need to change the function to accept a pointer.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM