C++primer plus第三章笔记

  • short是short int的简称,long是long int的简称unsigned是unsigned int的缩写。
  • #define编译指令的工作方式与文本编辑器的全局搜索并替换相似。
  • C++采用前一二位来表示数字常量的基数
    • 第一位是1-9:十进制
    • 第一位是0,第二位是1-7:八进制 eg.042
    • 前两位为0x或0X:十六进制 eg.0x42
  • 默认情况下,不管程序中怎么书写cout以十进制显示整数,使用dex、hex、oct可以改变输出进制 eg. cout << oct << i;//以十六进制输出
  • cout与cout.put区别:
cout << '$';   //打印ASCII码!
cout.put('$'); //打印字符$!
  • 任何非零值都可被隐式转换成true eg. bool b = -100;//b赋值为true
  • const与#define区别:
    • 能明确类型
    • 可将定义限制在特定作用域
    • 可将const用于更复杂的类型如数组和结构
  • 初始化声明中,使用关键字auto而不指定变量的类型,编译器会把变量的类型设置成与初始值相同
auto x = 0.0; //x为double类型
auto y = 0;  //y为int类型
  • 整数从小到大依次是:bool, char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsiged long long。

你可能感兴趣的:(c++primer-plus)