C++基础篇

来源:互联网 发布:淘宝分享有礼活动效果 编辑:程序博客网 时间:2024/06/04 22:24

1.  变量和类型

      一共有4种类型,character types, numerical integer types,floating-point types,boolean type。

      每种类型所占字节数:

GroupType names*Notes on size / precisionCharacter typescharExactly one byte in size. At least 8 bits.char16_tNot smaller than char. At least 16 bits.char32_tNot smaller than char16_t. At least 32 bits.wchar_tCan represent the largest supported character set.Integer types (signed)signed charSame size as char. At least 8 bits.signed short intNot smaller than char. At least 16 bits.signed intNot smaller than short. At least 16 bits.signed long intNot smaller than int. At least 32 bits.signed long long intNot smaller than long. At least 64 bits.Integer types (unsigned)unsigned char(same size as their signed counterparts)unsigned short intunsigned intunsigned long intunsigned long long intFloating-point typesfloat doublePrecision not less than floatlong doublePrecision not less than doubleBoolean typebool Void typevoidno storageNull pointerdecltype(nullptr) 

2. 初始化方法:

    有3种: 

     (1) type identifier = initial_value; 

     (2) type identifier(initial_value);

     (3) type identifier{initial_value};

     举例: int x=0;  int x(0); int x{0}; 这三种方法都是给x赋值为0.

     同样的, string mystring = "This is a string!";

                      string mystring("This is a string!");

                      string mystring{"This is a string!"};

3. 常量的定义方法

    有2种方法:

    (1) 用const关键字来定义一个常量.  

    (2) 用预定义#define的方法, #define identifier replacement

     举例   const double pi = 3.14159; 

                #define pi 3.14159;

4. 操作符

     LevelPrecedence groupOperatorDescriptionGrouping1Scope::scope qualifierLeft-to-right2Postfix (unary)++ --postfix increment / decrementLeft-to-right()functional forms[]subscript. ->member access3Prefix (unary)++ --prefix increment / decrementRight-to-left~ !bitwise NOT / logical NOT+ -unary prefix& *reference / dereferencenew deleteallocation / deallocationsizeofparameter pack(type)C-style type-casting4Pointer-to-member.* ->*access pointerLeft-to-right5Arithmetic: scaling* / %multiply, divide, moduloLeft-to-right6Arithmetic: addition+ -addition, subtractionLeft-to-right7Bitwise shift<< >>shift left, shift rightLeft-to-right8Relational< > <= >=comparison operatorsLeft-to-right9Equality== !=equality / inequalityLeft-to-right10And&bitwise ANDLeft-to-right11Exclusive or^bitwise XORLeft-to-right12Inclusive or|bitwise ORLeft-to-right13Conjunction&&logical ANDLeft-to-right14Disjunction||logical ORLeft-to-right15Assignment-level expressions= *= /= %= += -=
>>= <<= &= ^= |=
assignment / compound assignmentRight-to-left?:conditional operator16Sequencing,comma separatorLeft-to-right

0 0
原创粉丝点击