⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 20-1.txt

📁 《C/C++完美演绎》源代码
💻 TXT
字号:
/* 范例:20-1 */
// 0.0 File scope 开始
#include <iostream.h>
#include <conio.h>

void fun_a(int a,int b);	/* 1 函数原型scope(参数行属于此),其中 
                      a,b的可见度仅限于原型声明( )内  */
void main(void)
{
  int i = 1;
  {	// 2.1 区块scope 开始
    cout << i << "\n";	// 输出main()区块定义的变量i
    int i = 2;
    cout << i << "\n";	// 输出区块scope(2.1~2.2)内定义的变量i
  }	// 2.2 区块scope 结束

  if(int m=3)	// 3.1 if条件scope 开始
    cout << m << "\n";	// 3.2
  else
    cout << (m+2) << "\n";	// 3.3 if条件scope 结束

  cout << "离开while请按Q/q\n";
  while(char ch=getch())	// 4.1 while条件scope 开始
  {
    if((ch=='q')||(ch=='Q'))
      break;
    putchar(ch);
  }	// 4.2 while条件scope 结束

  switch(char ch=getch())	// 5.1 switch条件scope 开始
  {
    case 'q':
      cout << "switch break!\n";
      break;
    // case 'q':	// Label case 不可重复
    default:
      cout << "按了" << ch << "\n";
    }	// 5.2 switch条件scope 结束
  KK:	// 6 main()中函数scope(Label KK)
    cout << "\nKK in main()\n";
  fun_a(1,2);

  getchar();
}

void fun_a(int a,int b)	// 7.1 区块scope 开始(含参数行)
{
  cout << (a+b) << "\n";
  KK:	// 8 fun_a()中函数scope(Label KK)
    cout << "KK in fun_a\n";
}	// 7.2 区块scope 结束
	// 0.1 File scope 结束

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -