基本数据类型与输入输出.pptx
第二章基本数据类型与输入输出
目录2.1字符集与保留字2.2基本数据类型2.3变量定义2.4常量2.5常量定义2.6I/O流控制
26个小写字母abcdefghijklmnopqrstuvwxyz10个数字0123456789其他符号+-*/=,._;?\“‘~|!#%()[]{}^(空格)26个大写字母ABCDEFGHIJKLMNOPQRSTUVWXYZ2.1字符集与保留字—字符集
2.1字符集与保留字—关键字AutoBreakCaseCharConstContinueDefaultDoDoubleElseEnumExternFloatForGotoIfIntLongRegisterReturnShortSignedSizeofStaticStructSwitchTypedefUnionUnsignedVoidVolatileWhileBoolCatchClassConst_castDeleteDynamic_castExplicitFalseFriendInlineMutableNamespaceNewOperatorPrivateProtectedPublicReinterpret_castStatic_castTemplateThisThrowTrueTryTypeidTypenameUsingVirtualWchar_tAsmCdeclFarHugeInterruptNearPascalExportExceptFastcallSaveregsStdcallSegSyscallFortranthread
在程序中,数据以变量或常量的形式来描述;变量是存储信息的单元,它对应于某个内存空间;用变量名代表其存储空间,程序可以在变量中存储值和取出值;定义变量时,必须说明变量的名字和数据类型;例:inta;2.2基本数据类型—数据
2.2基本数据类型数据类型基本数据类型非基本数据类型整型int字符型实型逻辑型bool指针type*空类型void结构struct联合union枚举enum数组type[]类class单字符型char宽字符型w_char单精度型float双精度型double
Short只能修饰int01Long只能修饰int和double02Signed和unsigned只能修饰int和char03长型符long04短型符short05有符号signed06无符号unsigned07修饰关系:2.2基本数据类型—修饰符
2.2基本数据类型—表示范围类型说明长度(字节)表示范围Char字符型1-128~127Unsignedchar无符号字符型10~255Signedchar有符号字符型1-128~127Int整型4-2147483648~2147483647Unsignedint无符号整型40~4294967295Signedint有符号整型4-2147483648~2147483647Shortint短整型2-32768~32767Unsignedshortint无符号短整型20~65535Signedshortint有符号短整型2-32768~32767Longint长整型4-2147483648~2147483647Signedlongint有符号长整型4-2147483648~2147483647Unsignedlongint无符号长整型40~4294967295Float浮点型4-3.4*1038~3.4*1038Double双精度型8-1.7*10308~1.7*10308Longdouble长双精度型8-1.7*10308~1.7*10308备注:这些是在VisualC++上面的定义。
布尔型变量的值为true和false;整型数与布尔变量的转换:非0整数隐式转换成true,整数0隐式转换成false;true转换成1,false转换成0;2.2基本数据类型—bool
2.2基本数据类型—sizeof操作符语法形式:sizeof(类型名)或sizeof(表达式)结果值:“类型名”所指定的类型或“表达式”的结果类型所占的字节数。
2.2基本数据类型—sizeof操作符#includeiostream.hvoidmain(){ coutint=sizeof(int)endl; coutchar=sizeof(char)endl; coutfloat=sizeof(float)endl; coutdouble=sizeof(double)endl; coutbool=sizeof(bool)endl; coutlongint=sizeof(longint)endl; coutlongdouble=s