C++基础篇
来源:互联网 发布:淘宝分享有礼活动效果 编辑:程序博客网 时间:2024/06/04 22:24
1. 变量和类型
一共有4种类型,character types, numerical integer types,floating-point types,boolean type。
每种类型所占字节数:
char
Exactly one byte in size. At least 8 bits.char16_t
Not smaller than char
. At least 16 bits.char32_t
Not smaller than char16_t
. At least 32 bits.wchar_t
Can represent the largest supported character set.Integer types (signed)signed char
Same size as char
. At least 8 bits.signed short int
Not smaller than char
. At least 16 bits.signed int
Not smaller than short
. At least 16 bits.signed long int
Not smaller than int
. At least 32 bits.signed long long int
Not smaller than long
. At least 64 bits.Integer types (unsigned)unsigned char
(same size as their signed counterparts)unsigned short int
unsigned int
unsigned long int
unsigned long long int
Floating-point typesfloat
double
Precision not less than float
long double
Precision not less than double
Boolean typebool
Void typevoid
no 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. 操作符
::
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 delete
allocation / deallocationsizeof
parameter 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
- C语言程序设计基础篇
- C语言基础篇LessonOne
- C基础知识--指针基础篇
- C++---基础篇(函数)
- C++---基础篇(数组)
- C++---基础篇(指针)
- object-c 入门基础篇
- C/C++面试---基础篇
- object-c 入门基础篇
- object-c 入门基础篇
- object-c 入门基础篇
- C语言 基础篇 printf
- C语言基础篇(四)
- C语言基础篇(五)
- object-c 入门基础篇
- objective-c - 基础篇 - UIWebView
- object-c 入门基础篇
- object-c 入门基础篇
- 英文论文词汇短语句式总结
- python里面Nose和pytest的区别
- 关于直播,所有的技术细节都在这里了
- The linux command line--part 4 Writing Shell Scripts
- SQL注入
- C++基础篇
- python3字符串连接方法效率测试
- ObjectArx 窗体显示错乱
- Java五个最常用的集合类之间的区别和联系
- Ant-design 快速上手
- linux文件解压
- 缓存
- SYS_GUID()与sequence的比较
- 数据预处理与特征选择