高手们 谁能把C++中的关键字及其每个关键字的用法和意思帮我总结一下嘛,我很多不知道,谢谢呀。

作者&投稿:种博 (若有异议请与网页底部的电邮联系)
c++中所有关键字的发音和意思,要详细!!!!~

发音...? 同英语发音.

意思...? 这个嘛,要想回答完善,需要一本 600页左右的 a4 大小的书吧。

32个关键字详解第一个关键字:auto 用来声明自动变量。可以显式的声明变量为自动变量。只要不是声明在所有函数之前的变量,即使没加auto关键字,也默认为自动变量。并且只在声明它的函数内有效。而且当使用完毕后,它的值会自动还原为最初所赋的值。自动变量使用时要先赋值,因为其中包含的是未知的值。例:auto int name=1; 第二个关键字:static 用来声明静态变量。可以显式的声明变量为静态变量。也为局部变量。只在声明它的函数内有效。它的生命周期从程序开始起一直到程序结束。而且即使使用完毕后,它的值仍旧不还原。即使没有给静态变量赋值,它也会自动初始化为.例:static int name=1. 第三个关键字:extern 用来声明全局变量。同时声明在main函数之前的变量也叫全局变量。它可以在程序的任何地方使用。程序运行期间它是一直存在的。全局变量也会初始化为.例:extern int name; 第四个关键字:register 用来声明为寄存器变量。也为局部变量,只在声明它的函数内有效。它是保存在寄存器之中的。速度要快很多。对于需要频繁使用的变量使用它来声明会提高程序运行速度。例:register int name=1; 第五个关键字:int 用来声明变量的类型。int为整型。注意在位和位系统中它的范围是不同的。位中占用个字节。位中占用个字节。还可以显式的声明为无符号或有符号:unsigned int signed int .有符号和无符号的区别就是把符号位也当作数字位来存储。也可用short和long来声明为短整型,或长整行。例:int num; 第六个关键字:float 用来声明变量的类型。float为浮点型,也叫实型。它的范围固定为个字节。其中位为小数位。其他为整数位。例:float name; 第七个关键字:double 用来声明为双精度类型。它的范围为个字节。位为小数位。也可使用更高精度的long double 它的范围则更大,达到字节。例:double name; 第八个关键字:struct 用来声明结构体类型。结构体可以包含各种不同类型的量。比如可以把整型,字符型等类型的变量声明在同一个结构体种,使用的时候使用结构体变量直接可以调用。例: struct some{ int a=1; float b=1.1; double=1.1234567;}kkk; 这样就可以使用kkk.a来使用结构体中的成员变量了。也可以显式的用struct some aaa,bbb;来声明多个结构体变量。 第九个关键字:char 用来定义为字符型变量。它的范围通常为个字节。它在内存中是以ASC||玛来表示的。所以它也可以跟整型来运算。也可使用无符号或有符号来定义。sigened char unsigned char例:char c; 第十个关键字:break 用来表示中断。一般用在循环中。判断是否满足条件然后中断当前循环。例:break; 第十一个关键字:continue 用来表示跳过当前其后面的语句,继续下一次循环。例:continue; 第十二个关键字:long 用来声明长型的类型。比如long int long double . 第十三个关键字:if 判断语句,用来判断语句是否满足条件,例: if a==b k=n; 第十四个关键字:switch 条件选择语句,常用来判断用户选择的条件来执行特定语句。例: switch (name){case ok: printf("yes,ok!"); break; case no: printf("oh,no!"); default: printf("error..!"); break;} 第十五个关键字:case 配合switch一起使用,例子同上。 第十六个关键字:enum 用来声明枚举变量。.. 例:enum day{one,two,three,four,five,six,seven }; 第十七的关键子:typedef 类型重定义..可以重定义类型,例:typedef unsigned int u_int; //将无符号整形定义为u_int . 第十八个关键字:return; 返回语句。可以返回一个值。当我们定义一个函数为有返回值的时候则必须返回一个值。 第十九个关键字:unio 定义联共用体。用法用struct相同。不同的是共用体所有成员共享存储空间. unio kkk{ int a; float b;}kka; 第二十个关键字:const 定义为常量.. 例:const int a; //变量a的值不能被改变. 第二十一个关键字:unsigned 定义为无符号的变量.. 默认变量都为有符号的.除非显示的声明为unsigned的. 第二十二个关键字:for 循环语句.可以指定程序循环多少次. 例: for (int i=0;i1) printf("a>1"); 第三十一个关键字:else 常用来配合if一起使用。例: if (a==b) k=n; else k=s; 第三十二个关键字:short用于声明一个短整型变量: 例:short int a;

(1)asm
asm已经被__asm替代了,用于汇编语言嵌入在C/C++程序里编程,从而在某些方面优化代码.虽然用asm关键字编译时编译器不会报错,但是asm模块的代码是没有意义的.

(2)auto
这个这个关键字用于声明变量的生存期为自动,即将不在任何类、结构、枚举、联合和函数中定义的变量视为全局变量,而在函数中定义的变量视为局部变量。这个关键字不怎么多写,因为所有的变量默认就是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 switch statement.

(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成员函数的声明中,const关键字只能放在函数声明的尾部,表示该类成员不修改对象.
说明:
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; a default label is present.Control is transferred to the default label.

(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.

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

(21)extern
extern 意为“外来的”···它的作用在于告诉编译器:有这个变量,它可能不存在当前的文件中,但它肯定要存在于工程中的某一个源文件中或者一个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 a const member function.

(32)namespace

Dynamically imports an element behavior into a document.

(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.

(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.

(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.

(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.

(38)register
声明积存器变量.The register keyword specifies that the variable is to be stored in a machine register, if possible.这个关键字命令编译器尽可能的将变量存在CPU内部寄存器中,而不是通过内存寻址访问,从而提高效率。

(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.

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

(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.

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

(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 using declaration appears.

(52)virtual

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

(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
说明变量在程序执行中可被隐含地改变,表明某个变量的值可能在外部被改变,优化器在用到这个变量时必须每次都小心地重新读取这个变量的值,而不是使用保存在寄存器里的备份。The volatile 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.

(55)wchar_t
宽字.

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


斗门区15561133222: C++中的关键字都有哪些? -
博蔡地奥: 使该类或者函数成为友元类或友元函数.在外部就可以访问到正常情况下无法访问到的私有属性和方法.有本书上大概是这样说的:C++的封装就像是一堵墙,可以保证墙里面物品的安全.友元就像是在墙上装了一扇门,这样就可以通过这扇门进入墙里面,使用里面的东西.这样做在某些情况下会让你很方便,但是它破坏了C++的封装性,所以要慎用.

斗门区15561133222: C++中的关键字 -
博蔡地奥: C++中共有74个关键字 保留字.and and_eq asm auto bitand bitor bool break case catch char class compl const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long ...

斗门区15561133222: C++中各种关键字的作用? -
博蔡地奥: auto :声明自动变量 一般不使用 double :声明双精度变量或函数 int: 声明整型变量或函数 struct:声明结构体变量或函数 break:跳出当前循环 else :条件语句否定分支(与 if 连用) long :声明长整型变量或函数 switch :用于开关语句 case...

斗门区15561133222: c++中所有关键字的发音和意思,要详细!!!! -
博蔡地奥: asm[1] 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 ...

斗门区15561133222: c++语言的所有关键字和解释.是c++的..多谢了 -
博蔡地奥: C/C++ 关键字asm语法: asm( "instruction" );asm允许你在你的代码中直接插入汇编语言指令, 各种不同的编译器为这一个指令允许不一致形式, 比如: asm { instruction-sequence }or asm( instruction );auto 关键字auto是用来声明完全可选择...

斗门区15561133222: 谁有C++的关键字的通俗解释 -
博蔡地奥: 关键字就是保留字,系统专用字

斗门区15561133222: C++程序中的关键字是什么意思?
博蔡地奥: C++程序中中76个关键字:abstract as base bool breakbyte case catch char checkedclass const continue decimal defaultdelegate do double else enumevent explicit extern false finallyfixed float for foreach gotoif implicit in int interface...

斗门区15561133222: C++63个关键字 -
博蔡地奥: 这个问题很简单,百度一下就知道了, (1)auto 这个这个关键字用于声明变量的生存期为自动,即将不在任何类、结构、枚举、联合和函数中定义的变量视为全局变量,而在函数中定义的变量视为局部变量.这个关键字不怎么多写,因为所有...

斗门区15561133222: 谁知道C++中关键字的诠释啊?
博蔡地奥: int 正数型 char 字符型(字符 、字母、数字的字符意义) bool 布尔型 (只有真、假两个逻辑判断值)

斗门区15561133222: C++关键字 -
博蔡地奥: (1)auto这个这个关键字用于声明变量的生存期为自动,即将不在任何类、结构、枚举、联合和函数中定义的变量视为全局变量,而在函数中定义的变量视为局部变量.这个关键字不怎么多写,因为所有的变量默认就是auto的.(2)register这个...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网