【发布时间】:2022-11-16 11:52:09
【问题描述】:
交换两个号码。通过使用指针。
int main()
{
int *a;
int *b;
a = 3;
b = 5;
*a=b;
*b=a;
printf("a=%d\n b=%d\n", *a, *b);
// It is showing Segmentation fault at line "*a=b(7)"
// I tried to introduce a new variable and assign it to *a and *b but it still shows the same error.
【问题讨论】:
-
如果您没有看到此代码的编译错误,请在执行任何其他操作之前修复您的编译器选项。运行错误的程序完全是浪费时间
-
“从‘int’赋值给‘int*’使得指针来自整数而不进行强制转换。”这是它给出的编译错误