我在一本教科书中看到了以下 C 代码片段,它工作正常...但我不明白输出以及为什么它工作正常,因为它看起来错误:
#include <stdio.h>
int main()
{
struct {
int x,y;
} s[4] = {{10,20},{15,25},{8,75},{6,2}};
int *i;
i=s;
clrscr();
printf("\n%d",s[i[7]].x);
printf("\n%d",i[i[1]-i[2]]);
printf("\n%d",i[s[3].y]);
printf("\n%d",(s+1)->x+5);
printf("\n%d",s[i[0]-i[4]].y + 10);
printf("\n%d",++i[i[6]]);
getch();
return 0;
}
而且我不明白如何在语句中将整数指针分配给 s
i=s;
最佳答案
Also i do not understand how we can assign an integer pointer to s in the statement:
i=s;
很简单,在 C 语言中没有强制转换就不行。你的编译器很友善地接受这样的程序,但其他编译器有权拒绝编译该程序。
关于c - 将整数指针分配给结构数组并且代码仍然被执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11065135/