全部问题 > 当前问题

怎么样区别先输出fun1还是fun2?


游科顺 2016-5-4 16:59:43

共 1 个回答

嘿嘿大人 2016-5-5 00:11:34

主函数里面先执行的是调用fun1然后才是fun2

问题来自: 形参和实参
有以下程序:
#include <stdio.h>
int a=1,b=2;
void fun1(int a, int b)
{ printf("%d%d",a,b); }
void fun2()
{ a=3; b=4; }
main()
{ fun1(5,6); fun2();
  printf("%d%d\n",a,b);
}
程序运行后的输出结果是 ______ 。
A. 1256
B. 5634
C. 5612
D. 3456
答案:B
解析:fun1输出的是形参a、b,所以输出56;fun2赋值的是全局变量a、b,在一个源文件中,全局变量被“屏蔽”,所以最后输出34。连在一起是5634。因此选B。