#include<stdio.h>
#include<conio.h>
void change(int *);
int main()
{
int a[5] = {1,2,3,4,5};
int i;
clrscr();
change(a);
for(i=4;i>=0;i--)
{
printf("%d\n",a[i]);
}
getch();
return 0;
}
void change(int *b)
{
int i;
for(i=0;i<=4;i++)
{
b=*b+1; //showing nonportable pointer exception
b++;
}
}
输出不符合预期,没有错误和 1 个警告....
预期输出:65432
当前输出:54321
最佳答案
b
的类型为 int *
,而 *b + 1
的类型为 int
。您正在将 int
类型分配给指针类型。改变
b=*b+1;
到
*b = *b+1;
关于c - 非可移植指针转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21369459/