1.C关键字63个关键字目前认识的关键字ifreturncontinueautodoubleshorttypedeffordoolintsignedpubilcbreakelselongsizeofcasestaticnamespaceunsigneddefaultcharnewstructusingfriendclassexternoperatorswitchconstfalseprivatevoidtruefloatprotectedthiswhilegototypenameenum不认识的asmdotryinlinedynamic-casttypeidthrowmutableunionwchar-tcatchexplicitstatic-caseexportvirtualregistertemplateconst-castvolatiledeletereinterpret_cast2.命名空间使用命名空间的目的是对标识符的名称进行本地化以避免命名冲突或名字污染。namespace2.1命名空间的定义namespace 命名空间名字{}2.1.1普通命名空间命名空间中既可以定义变量也可以定义函数namespace X { int i; void print(int c) { coutcendl; } }2.1.2命名空间可以嵌套namespace Y { int i; void print1(int c) { coutcendl; } namespace z { int i; void print2(int c) { coutcendl; } } }2.1.3多个相同名称的命名空间同一工程中允许存在多个相同名称的命名空间编译器最后会合成到同一个命名空间中。namespace X { int i; void print(int c) { coutcendl; } } namespace X { int a; void print3(int c) { coutcendl; } }一个命名空间就定义了一个新的作用域命名空间中所有内容都局限于该命名空间中2.2命名空间的使用有三种使用方式2.2.1加命名空间名称及类作用域限定符namespace X { int i; void print(int c) { std::coutcstd::endl; } }2.2.2用using将命名空间中成员引入using std::cout; using std::endl; namespace X { int i; void print(int c) { coutcendl; } }2.2.3用using namespace 命名空间名称引入using namespace std; namespace X { int i; void print(int c) { coutcendl; } }项目中用第二种日常练习用第三种3.输入输出#includeiostream using namespace std; int main() { int e; cine; coute1endl; return 0; }4.缺省参数缺省参数是声明或定义函数是为函数的参数指定一个默认值。分为全缺省参数和半缺省参数4.1全缺省参数#includeiostream using namespace std; void print(int x1,int y2,int z3) { coutx--xendl; couty--yendl; coutz--zendl; } int main() { print(2); print(4,5); print(5,6,7); return 0; }4.2半缺省参数#includeiostream using namespace std; void print(int x,int y,int z3) { coutx--x ; couty--y ; coutz--z endl; } int main() { print(4,5); print(5,6,7); return 0; }1.半缺省参数必须从右往左依次给出不能间隔着隔2.缺省参数不能在函数声明和函数定义中同时出现如果同时出现且两个位置提供的值不同编译器就无法确定该用哪个缺省值3.缺省参数必须是常量或者全局变量4.C语言不支持5.函数重载5.1重载的实现参数个数、类型、顺序不同如果只有返回值不同不算函数重载/*double print(double x,double y,double z) { coutx--x ; couty--y ; coutz--z endl; } float print(double x,double y,double z) { coutx--x ; couty--y ; coutz--z endl; }*/#includeiostream using namespace std; void print(int x,int y,int z) { coutx--x ; couty--y ; coutz--z endl; } void print(double x,double y,double z) { coutx--x ; couty--y ; coutz--z endl; } void print(int x,double y,long z) { coutx--x ; couty--y ; coutz--z endl; } int main() { print(1,2,3); print(4.0,5.0,6.0); print(7,8.0,9L); return 0; }5.2 extern C在函数面前加 externC ,就是让编译器按照C语言的规则来编译。extern C double print(double x,double y,double z) { coutx--x ; couty--y ; coutz--z endl; }