用extern对变量作外部变量声明:
#include<iostream>
using namespace std;
int max(int, int);
int main()
{
extern int a, b;
cout << max(a, b) << endl;
return 0;
}
int a = 15, b = -7;
int max(int x, int y)
{
int z;
z = x > y ? x : y;
return z;
}
执行效果如图:
用extern对变量作外部变量声明:
#include<iostream>
using namespace std;
int max(int, int);
int main()
{
extern int a, b;
cout << max(a, b) << endl;
return 0;
}
int a = 15, b = -7;
int max(int x, int y)
{
int z;
z = x > y ? x : y;
return z;
}
执行效果如图: