一. C++基础知识点
-
单位转换
1字=2字节Byte=16位(比特)bit 1字节=8位(比特)bit
1 Byte(B)= 8 bit;
1 Kilo Byte(KB) = 1024B;
1 Mega Byte(MB) = 1024 KB;
1 Giga Byte (GB)= 1024 MB;
1 Tera Byte(TB)= 1024 GB;
1 Peta Byte(PB) = 1024 TB
-
基本数据类型
类型 关键字 布尔型 bool 字符型 char(unsigned,signed) 整型 int(signed,unsigned,short,long) 浮点型 float 双浮点型 double(long) 无类型 void 宽字符型 wchar_t 一些基本类型可以使用一个或多个类型修饰符进行修饰,signed(有符号,float和double总是带符号的)、unsigned(无符号)、long、short
signed:存储单元的最高位用来表示数值的符号,数值1表示负数,数值0表示正数;除char外,其他默认有符号,如果需要声明无符号需要带关键字unsigned int/float…
unsigned:默认无符号的有char
short、long:会改变字节大小,signed和unsigned不会
类型 位 范围 char 1 个字节=8bit -128 到 127 或者 0 到 255 unsigned char 1 个字节 0 到 255 signed char 1 个字节 -128 到 127 int 4 个字节=32bit -2147483648 到 2147483647 unsigned int 4 个字节 0 到 4294967295 signed int 4 个字节 -2147483648 到 2147483647 short int 2 个字节=16bit -32768 到 32767 unsigned short int 2 个字节 0 到 65,535 signed short int 2 个字节 -32768 到 32767 long long int 8 个字节 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 signed long int 8 个字节 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 unsigned long int 8 个字节 0 to 18,446,744,073,709,551,615 float 4 个字节 +/- 3.4e +/- 38 (~7 个数字) double 8 个字节 +/- 1.7e +/- 308 (~15 个数字) long double 16 个字节 +/- 1.7e +/- 308 (~15 个数字) wchar_t 2 或 4 个字节 1 个宽字符 -
代码验证
#include<iostream> using namespace std; int main() { cout << "查看编译器位数:" << endl; cout << "Size of point : " <<sizeof(void*) *8<< endl; cout << "Size of char : " << sizeof(char) << endl; cout << "Size of signed char : " << sizeof(signed char) << endl; cout << "Size of unsigned char : " << sizeof(unsigned char) << endl; cout << "int : "<<endl; cout << "Size of int : " << sizeof(int) << endl; cout << "Size of signed int : " << sizeof(signed int) << endl; cout << "Size of unsigned int : " << sizeof(unsigned int) << endl; cout << "Size of short int : " << sizeof(short int) << endl; cout << "Size of long int : " << sizeof(long int) << endl; cout << "Size of long long : " << sizeof(long long int) << endl; cout << "float : "<<endl; cout << "Size of float : " << sizeof(float) << endl; cout << "double : "<<endl; cout << "Size of double : " << sizeof(double) << endl; cout << "Size of long double : " << sizeof(long double) << endl; cout << "Size of wchar_t : " << sizeof(wchar_t) << endl; return 0; }
- 待补充