gpt4 book ai didi

c - 错误: Incompatible integer to pointer conversion passing 'unsigned long'

转载 作者:行者123 更新时间:2023-11-30 20:26:40 27 4
gpt4 key购买 nike

将指向长整数的指针作为函数参数传递时,我收到以下警告消息。

warning: incompatible integer to pointer conversion passing 'unsigned long' to parameter of type 'unsigned long *'; remove * [-Wint-conversion] reverse(*n1);

Recursion_Reverse.c:16:29: note: passing argument to parameter 'n1' here: void reverse(unsigned long *n1)

这是代码片段。提前致谢!

void reverse(unsigned long *);

int main() {
unsigned long n;

printf("\nEnter Any Nnmber:");
scanf("%lu",&n);

reverse(&n);
printf("\nAfter Reverse,n=%lu\n",n);

return 0;
}


void reverse(unsigned long *n1) {
unsigned long sum=0;
if(*n1>0)
{
sum=(sum*10)+(*n1%10);
*n1/=10;
reverse(*n1);
}

*n1=sum;
}

最佳答案

从您的 void reverse(unsigned long *n1) 函数内部,您递归地调用它:

reverse(*n1);

因此,您传递的是直接 unsigned long 而不是其指针。正如您所期望的,只需将其指针更改为:

reverse(n1);

关于c - 错误: Incompatible integer to pointer conversion passing 'unsigned long' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24839186/

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