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

 

转载于:https://www.cnblogs.com/borter/p/9413183.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值