面向对象程序设计 2.字符串对双引号括起来的字符序列 例4:“ this is a string 3.标识符由程序设计者确定的名字 堂提要 包括:常量名、变量名、 函数名、类名等等。 第五章C++基础 51C++概述 例5: const pi;中的pi 52数据和表达式 中的 53基本语句 void add()中的add 54函数 class student(1;中的 student55数组与指针
第五章 C++基础 5.1 C++概述 5.2 数据和表达式 5.3 基本语句 5.4 函数 5.5 数组与指针 2. 字符串 一对双引号括起来的字符序列 例4:“this is a string” 3. 标识符 由程序设计者确定的名字、 包括:常量名、变量名、 函数名、类名等等。 例5: const pi; 中的 pi int x; 中的 x void add( ); 中的 add class student{……}; 中的 student
面向对象程序设计 标识符的构成 字母、数字和下划线 不能以数字开头,大小 写有区别。 例6: under bar,m9909,t5,b7,Bb等等 堂提要 问题:下列哪些是正确的标识符? 第五章C++基础 Her sales 51C++概述 MaDd 52数据和表达式 9 class 53基本语句 class 9 54函数 class 9 55数组与指针 2h
第五章 C++基础 5.1 C++概述 5.2 数据和表达式 5.3 基本语句 5.4 函数 5.5 数组与指针 标识符的构成 字母、数字和下划线 不能以数字开头,大小 写有区别。 例6:_under_bar, m9909, t5, b7, Bb等等 问题:下列哪些是正确的标识符? Her_sales ( ) MyAdd ( ) 9_class ( ) class_9 ( ) class 9 ( ) 2h ( ) ☺ ☺ ☺
面向对象程序设计 4.关键字系统定义的有特定作用的名字 C和C++都有(常用) int、 float、char、 struct、 union、 const、 堂提要 static、long、 short、 unsigned、 signed、 第五章C++基础 void、enum、 extern、 double、 typedef 51C++概述 for、if、dlse、 while、do、 switch、case、s2数据和表达式 default、 break、 continue、 return、soto53基本语句 54函数 1657: int x; float a; const pi=3.1415 55数组与指针 if(a==b)xa; else xb
第五章 C++基础 5.1 C++概述 5.2 数据和表达式 5.3 基本语句 5.4 函数 5.5 数组与指针 4. 关键字 系统定义的有特定作用的名字 C 和 C++ 都有 (常用) int、float、char、struct、union、const、 static、long、short、unsigned、signed、 void、enum、extern、double、typedef。 for、if、else、while、do、switch、case、 default、break、continue、return、 goto 例7:int x; float a; const pi=3.1415; if(a= =b) x=a; else x=b;
面向对象程序设计 问题?能否用关键字作标识符? 答案:不能!(为什么?) C++特有的关键字(常用) 堂提要 class: 定义类; public, private, protected 第五章C++基础 定义公共,私有,保护属性和服务;51C+概述 friend 定义友元 52数据和表达式 operator:定义运算符; 53基本语句 inline 定义内联函数; 54函数 virtual 定义虚函数; 55数组与指针 template:定义模板; new, delete:分配和消除存储空间 this 指向自己的指针
第五章 C++基础 5.1 C++概述 5.2 数据和表达式 5.3 基本语句 5.4 函数 5.5 数组与指针 问题 能否用关键字作标识符? 答案:不能!(为什么?) C++ 特有的关键字 (常用) class: 定义类; public, private, protected : 定义公共, 私有, 保护属性和服务; friend: 定义友元; operator: 定义运算符; inline: 定义内联函数; virtual: 定义虚函数; template: 定义模板; new, delete:分配和消除存储空间 this: 指向自己的指针