【发布时间】:2015-05-29 05:53:45
【问题描述】:
解释输出 .程序已经在gnu上编译(gcc 4.9.2编译器)
#include <stdio.h>
main()
{
int i=1;
int arr[]={2,3,4,5};
int x=(i++<3);
printf("%d %d %d %d %d",i,x,++i[arr],i++[arr],i);
}
输出:3 1 6 4 3
【问题讨论】:
-
这是未定义的行为。输出可以是任何东西。
-
@Amit ,实际上,它确实可以编译。但是有警告......
-
@CoolGuy
i[arr]会编译吗?不知道...它会翻译成什么? -
@Amit 看到这个问题:"With C arrays, why is it the case that
a[5]==5[a]?". -
@AyushNigam 没有对输出的解释。您的参数会引发对
i的未排序评估和修改。事实上,clang 甚至会警告你:“未排序的修改和访问 'i'”。如果 gcc 不考虑调高您的警告级别和选项。