在函数中传递 int 时,我得到不正确的结果:
int recruit(int var1, int re_unit, char *char_buffer, int var2) {
int run = 1;
int int_buffer = 0;
printf("Test1 %d\n", var1);
printf("Test2 %d\n", var2);
...
}
void some_other_function(structs, struct1[]) {
int var1 = 0;
int var2 = 0;
int re_unit = 0;
char char_buffer[] = "What ever";
//strucs[1].first = 50 this is done in a other section
var1 = strucs1[1].first;
var2 = strucs1[1].first;
recruit(var1, re_unit, char_buffer, var2);
// Ind the full verstion of the program this function is called 2 times:
// The first time nothing is worng, how ever the second time, the result
// is as explaned below
//strucs[2].first = 50 // this is done in a other section
var1 = struct1[2].first;
var2 = struct1[2].first;
recruit(var1, re_unit, char_buffer, var2);
}
int main(void) {
...
}
现在结果是第一次Test1打印:2684032,Test2打印:50
第二次测试 1 打印:2684032 和测试 2 打印:50;
他们都应该打印 50。
我已经测试了 struct1[1].first 的值是 50,然后才用于函数招募。
有谁知道为什么会发生这种情况?