1. 程式人生 > >‘,’之後要留空格,如 Function(x, y, z)

‘,’之後要留空格,如 Function(x, y, z)

user names fun return 調用函數 char float ace out

‘,’之後要留空格,如 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 }

‘,’之後要留空格,如 Function(x, y, z)