如果声明了 union,循环将不会显示
Loop won't display if union is declared
如果我包含 union test
的声明,为什么下面代码中的 for
循环似乎没有 运行?我正在使用 clang 编译器。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
union test{
int intv;
float floatv;
};
int main(){
union test test1; // When this is removed the below loop displays.
for(int i, j = 0; i < 5; i++, j = (j + i) * 2){
printf("%d %d\n", i, j);
}
return 0;
}
这是未定义的行为。您从未初始化 i
。
如果我包含 union test
的声明,为什么下面代码中的 for
循环似乎没有 运行?我正在使用 clang 编译器。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
union test{
int intv;
float floatv;
};
int main(){
union test test1; // When this is removed the below loop displays.
for(int i, j = 0; i < 5; i++, j = (j + i) * 2){
printf("%d %d\n", i, j);
}
return 0;
}
这是未定义的行为。您从未初始化 i
。