如我在函数中定义了一个变量a=0,函数中我将100赋予a,结束函数后,我重新调用该函数,为什么a不等于100而等于0呢,请高手指点!
下面是三个对这个问题的演示程序,你对照着看一下:
int function(int a);
main()
{
int a = 100;
function(a);
printf("In main : a = %d\n" ,a);
getch();
}
int function(int x)
{
x = 0;
printf("In function : x = %d\n" ,x);
}
-----------------------------------------------------
int function(int a);
int a = 100;
main()
{
function(a);
printf("In main : a = %d\n" ,a);
getch();
}
int function(int x)
{
x = 0;
a = 0;
printf("In function : x = %d\n" ,x);
printf("In function : a = %d\n" ,a);
}
-----------------------------------------------------
int function(int a);
int a = 100;
main()
{
function(a);
printf("In main : a = %d\n" ,a);
getch();
}
int function(int x)
{
int a;
x = 0;
a = 0;
printf("In function : x = %d\n" ,x);
printf("In function : a = %d\n" ,a);
}
回去把书再好好看一下