作用域的问题 谢谢大佬讲解
#include <stdio.h>
/* 全局变量声明 */
int a = 20;
int main (){
/* 在主函数中的局部变量声明 */
int a = 10;
int b = 20;
int c = 0;
int sum(int, int);
printf ("value of a in main() = %d\n", a);
c = sum( a, b);
printf ("value of c in main() = %d\n", c);
return 0;
}
/* 添加两个整数的函数 */
int sum(int a, int b){
printf ("value of a in sum() = %d\n", a);
printf ("value of b in sum() = %d\n", b);
return a + b;
}
为什么输出
value of a in main() = 10 value of a in sum() = 10 value of b in sum() = 20 value of c in main() = 30