gpt4 book ai didi

c - 返回链表第 n 个节点的函数的返回类型错误

转载 作者:行者123 更新时间:2023-11-30 20:15:53 25 4
gpt4 key购买 nike

这是一个返回链表第 n 个节点的函数,但是编译器不断错误提示返回类型应该是 int。这是为什么?

struct Node *getNthNode(struct Node* head, int index)
{
if (head==NULL)
return NULL;


struct Node *current = head;
int count = 0;
while (current)
{
if (count == index)
return(current);
count++;
current = current->next;
}

最佳答案

很可能您在声明函数之前就调用了该函数,因此它默认返回类型 int。我们必须查看整个文件才能确定。查找所有编译器警告。

int main() {
char* p;
p = foo(); // Compiler assumes default int return type
return 0;
}

char* foo() {
}

关于c - 返回链表第 n 个节点的函数的返回类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15629056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com