c - 我需要在符号前放什么?

标签 c pointers arguments ampersand

extractMin 的参数行出现以下错误:

randmst.c:129: 错误:在“&”标记之前需要“;”、“,”或“)”

如果我没有粘贴足够的代码导致错误明显,请告诉我。

//the heap functions

//based on p. 163 of clrs
VertexPointer
extractMin(VertexPointer *heap, int &heap_size){
    VertexPointer max = heap[0];
    (*heap[0]).key = 100;
    heap_size = heap_size - 1;
    minHeapify(heap, heap_size, 1);
    return max;
}

最佳答案

你不能在 C 中执行此 extractMin(VertexPointer *heap, int &heap_size) - 将其更改为 extractMin(VertexPointer *heap, int *heap_size)

C 中没有传递引用。所以你应该有这样的东西:

extractMin(VertexPointer *heap, int *heap_size){
    VertexPointer max = heap[0];
    (*heap[0]).key = 100;
    *heap_size = *heap_size - 1;
    minHeapify(heap, *heap_size, 1); 
    return max;
}

& 用于获取变量的地址,因此在调用函数时应这样调用:

extractMin(someAddress_to_heap, someAddress_to_heap_size)

关于c - 我需要在符号前放什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22242292/

相关文章:

c - 将链表保存并加载到二进制文件 (C)

用于生成 winexe 的 c 编译器命令

c - 难以理解MACRO的偏移量

python - 如何将未指定数量的参数传递给 lambda? (Python)

c++ - 系统日志不转发远程消息

c - 不兼容的指针类型函数

c++ - Boost:在 vector 中存储指向分布的指针

使用 getx 传递多个数据

bash - 如何使用 getopts 忽略无效参数并继续解析?

c - 用 C 语言编程 Arduino,中断 vector 会起作用吗?