c - 非可移植指针转换

标签 c arrays exception pointers warnings

#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/

相关文章:

c - 错误: expected identifier or ‘(’ before ‘.’ token

c - C 编程中 cos x 和 sin x 的泰勒级数展开,不使用 math.h 且仅在 int main() 内部

c - C 中的指针和链表

javascript - 每次单击 div 时更改正文背景颜色

java - 每次有 2 个元素的 for 循环中数组索引超出范围

javascript - 在 JavaScript 中比较数组中的对象 ID

javascript - Rhino 将 Java 类传递给 Javascript 函数

C 问题:另一个 while 循环内的 while(fgets) 循环仅执行一次

java - Exception.getMessage() 为空

c++ - throw() (即 __declspec(nothrow)) 是否在 Visual C++ 中提供了真正的好处?