‘,’之后要留空格,如 Function(x, y, z)
‘,’之后要留空格,如 Function(x, y, z)。如果‘;’不是一行的结束 符号,其后要留空格,如 for (initialization; condition; update)。
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 //声明全局变量并初始化 6 extern int a[]={1,2,3}; 7 extern float p=3.14; 8 9 //在show()函数中使用外部变量 10 show() { 11 int i; 12 cout<<"In show():"<<endl; 13 cout<<"p="<<p<<endl; 14 cout<<"a[]: "; 15 for (i=0;i<=2;i++) 16 cout<<a[i]<<" "; 17 cout<<endl; 18 //cout<<"y="<<y<<endl; 编译出错! 19 } 20 21 //声明外部变量并初始化 22 int y=5678; 23 24 int main(int argc, char** argv) { 25 26 //声明局部变量 27 int i,p=100; 28 29 //显示重名变量 30 cout<<"In main():"<<endl; 31 cout<<"p="<<p<<endl; 32 33 //显示全局变量 34 cout<<"::p="<<::p<<endl; 35 cout<<"a[]: "; 36 for (i=0;i<=2;i++) 37 cout<<a[i]<<" "; 38 cout<<endl; 39 cout<<"y="<<y<<endl; //编译正确! 40 41 show(); //调用函数 42 return 0; 43 }