有关全局变量的问题
#include<iostream>using namespace std;
int a=8,b=6;
int f(int a,int b)
{int c=a+b;
a=c;
b=a;
return c;
}
int main()
{int c;
c=f(a,b);
cout<<c<<" "<<a<<" "<<b<<endl;
return 0;}此结果全局变量a,b的值8,6不变
#include<iostream>
using namespace std;
float max=0,min=0;
float average(float score[],int n)
{int i;
float sum=score[0];
max=min=score[0];
for(i=1;i<n;i++)
{sum=sum+sorce[i];
if(max<score[i])max=score[i];
if(min>score[i])min=score[i];
}
return sum/n;
}
void main()
{float avg,score[10];
inti;
for(i=0;i<10,i++)
cin>>a[i];
avg=average(score,10)
cout<<max<<min<<avg;
return 0;}
此程序运行的结果max,min都变了,max,min只是两个变量,不是指针,为啥max,min的值都变了,
请高人指点