C++转义字符 & keyword

转义字符

换行符 \n  水平制表符\t
纵向制表符 \v退格符 \b
回车符 \r  进纸符 \f
报警(响铃)符 \a反斜线 \\
疑问号 \?单引號 \'
双引號 \" 


keyword

asm  =>__asm auto bad_cast bad_typeid
bool break case catch
char class const const_cast
continue default delete do
double dynamic_cast else enum
except explicit extern false
finally float for friend
goto if inline int
long mutable namespace new
operator private protected public
register reinterpret_cast return short
signed sizeof static static_cast
struct switch template this
throw true try type_info
typedef typeid typename union
unsigned using virtual void
volatile while    

keyword是预先保留的标识符,每一个keyword都有特殊的含义。我们不能在程序中使用与keyword同名的标识符。下面是C++所保留的关键

C++keyword全集(这个是从C++ Primer copy过来的,有一些补充,也有一些已经被替代):

(1)asm
asm已经被__asm替代了,用于汇编语言嵌入在C/C++程序里编程,从而在某些方面优化代码.尽管用asm关键

字编译时编译器不会报错,可是asm模块的代码是没有意义的.

(2)auto 
这个这个keyword用于声明变量的生存期为自己主动,即将不在不论什么类、结构、枚举、联合和函数中定义的变量

视为全局变量,而在函数中定义的变量视为局部变量。这个keyword不怎么多写,由于全部的变量默认就是

auto的。

(3)bad_cast,const_cast,dynamic_cast,reinterpret_cast,static_cast
关于异常处理的,还不是太了解..

(4)bad_typeid
也是用于异常处理的,当typeid操作符的操作数typeid为Null指针时抛出.

(5)bool
不用多说了吧,声明布尔类型的变量或函数.

(6)break
跳出当前循环.The break statement terminates the execution of the nearest enclosing loop or

conditional statement in which it appears.

(7)case
switch语句分支.Labels that appear after the case keyword cannot also appear outside a

switchstatement.

(8)catch,throw,try
都是异常处理的语句,The try, throw, and catch statements implement exception handling.

(9)char
声明字符型变量或函数.

(10)class
声明或定义类或者类的对象.The class keyword declares a class type or defines an object of a

class type.

(11)const
被const修饰的东西都受到强制保护,能够预防意外的变动,能提高程序的健壮性。它能够修饰函数的參

数、返回值,甚至函数的定义体。 
作用: 
1.修饰输入參数 
      a.对于非内部数据类型的输入參数,应该将“值传递”的方式改为“const引用传递”,目的是提

高效率。比如将void Func(A a) 改为void Func(const A &a)。 
      b.对于内部数据类型的输入參数,不要将“值传递”的方式改为“const引用传递”。否则既达不

到提高效率的目的,又减少了函数的可理解性。比如void Func(int x) 不应该改为void Func(const int

&x)。 
2.用const修饰函数的返回值 
      a.假设给以“指针传递”方式的函数返回值加const修饰,那么函数返回值(即指针)的内容不能

被改动,该返回值仅仅能被赋给加const修饰的同类型指针。 
如对于:const char * GetString(void); 
例如以下语句将出现编译错误: 
char *str = GetString();//cannot convert from 'const char *' to 'char *'; 
正确的使用方法是: 
const char *str = GetString(); 
      b.假设函数返回值採用“值传递方式”,因为函数会把返回值拷贝到外部暂时的存储单元中,加

const修饰没有不论什么价值。 如不要把函数int GetInt(void) 写成const int GetInt(void)。 
3.const成员函数的声明中,constkeyword仅仅能放在函数声明的尾部,表示该类成员不改动对象. 
说明: 
const type m; //修饰m为不可改变 
演示样例: 
typedef char * pStr; //新的类型pStr; 
char string[4] = "abc"; 
const char *p1 = string; 
p1++; //正确,上边修饰的是*p1,p1可变 
const pStr p2 = string; 
p2++; //错误,上边修饰的

是p2,p2不可变,*p2可变 
同理,const修饰指针时用此原则推断就不会混淆了。

const int *value; //*value不可变,value可变 
int* const value; //value不可变,*value可变 
const (int *) value; //(int *)是一种type,value不可变,*value可变 
//逻辑上这样理解,编译不能通过,须要tydef int* NewType; 
const int* const value;//*value,value都不可变

(12)continue
结束当前循环,開始下一轮循环.Forces transfer of control to the controlling expression of the

smallest enclosing do, for, or while loop.

(13)default
switch语句中的默认分支.None of the constants match the constants in the case labels;

adefault label is present.Control is transferred to the default label.

常量的无匹配情况下标签的常量;
adefault标签present.Control转移到默认的标签。


(14)delete
经经常使用于动态内存分配的语句,Deallocates a block of memory.


(15)do
在do-while循环结构中開始循环体.Executes a statement repeatedly until the specified

termination condition (the expression) evaluates to zero.

(16)double
声明双精度变量或函数.

(17)else
条件语句否定分支(与 if 连用).

(18)enum
声明枚举类型.The name of each enumerator is treated as a constant and must be unique within

the scope where the enum is defined.

(19)explicit

This keyword is a declaration specifier that can only be applied to in-class constructor

declarations. An explicit constructor cannot take part in implicit conversions. It can only

be used to explicitly construct an object.
这个keyword声明说明符,能够仅仅适用于同类构造函数声明。显式构造函数不能在隐式转换的一部分。它仅仅

能用于显式构造一个对象

(20)export
MSDN仅仅说The export keyword is not supported on templates.一种导出语句吧..

(21)extern
extern 意为“外来的”···它的作用在于告诉编译器:有这个变量,它可能不存在当前的文件里,但

它肯定要存在于project中的某一个源文件里或者一个Dll的输出中。声明变量是在其它文件里声明(也能够看

做是引用变量).Objects and variables declared as extern declare an object that is defined in

another translation unit or in an enclosing scope as having external linkage.

(22)false,true
bool类型的两个枚举值.

(23)float
声明浮点型变量或函数.

(24)for
一种循环语句(可意会不可言传).Use the for statement to construct loops that must execute a

specified number of times.

(25)friend
声明友元函数或者类.The friend keyword allows a function or class to gain access to the

private and protected members of a class.

(26)goto
无条件跳转语句.Performs an unconditional transfer of control to the named label.

(27)if
条件语句.Controls conditional branching.常与else一起用.

(28)inline
声明定义内联函数,编译时将所调用的代码嵌入到主函数中.The inline specifiers instruct the

compiler to insert a copy of the function body into each place the function is called.

(29)int
声明整型变量或函数.

(30)long
声明长整型变量或函数.

(31)mutable

This keyword can only be applied to non-static and non-const data members of a class. If a

data member is declared mutable, then it is legal to assign a value to this data member from

aconst member function.
这个keyword仅仅适用于非静态和非const数据类成员。假设一个
声明数据成员是可变的,那么它是合法的赋值从这个数据成员
aconst成员函数


(32)namespace

Dynamically imports an element behavior into a document.
动态导入到文档中的元素行为
c++中using namespace std


(33)new
动态内存分配.Allocates memory for an object or array of objects of type-name from the free

store and returns a suitably typed, nonzero pointer to the object.
分配内存的对象或数组类型的对象从自由的名义
存储和返回一个适当类型,非零对象的指针


(34)operator
The operator keyword declares a function specifying what operator-symbol means when applied

to instances of a class. 
经营者keyword声明一个函数指定经营什么符号意味着当应用
对一类的实例

(35)private

类私有函数和数据成员的标示.When preceding a list of class members, the private keyword

specifies that those members are accessible only from member functions and friends of the

class. This applies to all members declared up to the next access specifier or the end of

the class.
当上一类的成员,私人keyword列表
指定这些成员仅仅能从成员的职能和朋友訪问
类。这适用于全部成员宣布了下一个訪问符或结束

(36)protected
The protected keyword specifies access to class members in the member-list up to the next

access specifier (public or private) or the end of the class definition. 
受保护的keyword指定訪问类成员的成员名单,直至下一个
訪问说明符(公共或私营)或类定义结束

(37)public

訪问方式:When preceding a list of class members, the public keyword specifies that those

members are accessible from any function. This applies to all members declared up to the

next access specifier or the end of the class.
当上一类成员,市民keyword列表指定的
成员能够从不论什么功能。这适用于全部成员宣布到
明年訪问符或类的结束


(38)register 
声明积存器变量.The register keyword specifies that the variable is to be stored in a machine

register, if possible.这个keyword命令编译器尽可能的将变量存在CPU内部寄存器中,而不是通过内存寻

址訪问,从而提高效率。 
登记冊keyword指定变量是要在计算机中存储的
注冊,假设可能的话

(39)return
子程序返回语句(能够带參数,也看不带參数),返回函数调用点.Terminates the execution of a

function and returns control to the calling function (or, in the case of the main function,

transfers control back to the operating system). Execution resumes in the calling function

at the point immediately following the call.
终止运行的
功能及控制返回给调用函数(或者,在主函数的情况,
传输控制返回给操作系统)。恢复运行在调用函数
在点后马上致电


(40)short
声明短整型变量或函数.

(41)signed,unsigned
声明有符号类型变量或函数;声明无符号类型变量或函数.

(42)static
声明静态变量.When modifying a variable, the static keyword specifies that the variable has

static durationinitializes it to 0 unless another value is specified.
当改动一个变量,statickeyword指定的变量
静态durationinitializes为0,除非还有一个指定值

(43)struct
声明结构体变量或函数.struct 类型是一种值类型,通经常使用来封装小型相关变量组.
struct hello文件名称

(44)switch

Allows selection among multiple sections of code, depending on the value of an integral

expression.
同意选择多个之间的代码段,这取决于一个总体的价值
表达


(45)template
模板.The template declaration specifies a set of parameterized classes or functions. 
该模板声明指定的类或函数的參数化设置

(46)this
The this pointer is a pointer accessible only within the nonstatic member functions of a

class,struct, or union type. 
在该指针是一个指针訪问仅仅有在一个非静态成员函数
类,结构或联合类型

(47)typedef
用以给数据类型取别名.Introduces a name that, within its scope, becomes a synonym for the

type given by the type-declaration portion of the declaration.
引入了一个名称,在其范围内,成为一个同义词
该类型声明宣言的一部分给定类型

(48)typeid
typeid is used to get the Type for a type at compile time.
typeid用于获取一个类型的类型在编译时

(49)typename
Tells the compiler that an unknown identifier is a type.Use this keyword only in template

definitions.
告诉编译器是一个未知的标识符是一个type.Use这仅仅是在模板中的keyword
定义

(50)union
声明联合数据类型.A union is a user-defined data or class type that, at any given time,

contains only one object from its list of members (although that object can be an array or a

class type).
阿联盟是一个用户定义的数据类型或类,在不论什么特定时间,
仅仅包括其成员名单的对象(尽管这个对象能够是一个数组或
类类型)


(51)using
The using declaration introduces a name into the declarative region in which the

usingdeclaration appears.
使用声明的声明中引入了在该地区出现一个名称usingdeclaration

(52)virtual

声明虚基类或虚函数.The virtual keyword declares a virtual function or a virtual base class.
virtualkeyword声明了一个虚函数或虚基类


(53)void
声明函数无返回值或无參数,声明无类型指针.

When used as a function return type, the void keyword specifies that the function does not

return a value. When used for a function's parameter list, void specifies that the function

takes no parameters. When used in the declaration of a pointer, void specifies that the

pointer is "universal."

(54)volatile 
说明变量在程序运行中可被隐含地改变,表明某个变量的值可能在外部被改变,优化器在用到这个变量时

必须每次都小心地又一次读取这个变量的值,而不是使用保存在寄存器里的备份。Thevolatile keyword is

a type qualifier used to declare that an object can be modified in the program by something

such as the operating system, the hardware, or a concurrently executing thread.
Thevolatilekeyword
一个类型限定符用来声明一个对象能够在程序中改动的东西
如操作系统,硬件或并发运行线程。


(55)wchar_t
宽字.

(56)while
循环语句的循环条件

(57)class

转自: http://hi.baidu.com/08172028/blog/item/0780f4045347d38ae850cde4.html

转载于:https://www.cnblogs.com/mengfanrong/p/3844072.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值