C ++ Primer point of attention

endl:
plus the ability to flush the buffer when debugging;
you can use the test excu <infile >outfileto file redirection

char:
char type of sign is determined by the presence or absence of the compiler, if you want to store small integers, it is best to explicitly specify the type.

Type selection:
1, specifically when the value is not negative selection unsigned;
2, usually selected int, int selected over Long Long;
. 3, floating point selection double, which is approximately the speed of the float, generally do not have long double

Type conversion:

bool b = 42;   //值为true
int i = b;  //值为1
i = 3.14;  //值为3
double pi = i;   //值为3.0
unsigned char = -1  //值为255,超出范围时相当于对其可表示范围256取余
signed char = 256  //值未定义

Never mix signed and unsigned types:
Here Insert Picture Description
Here Insert Picture Description
literal specified type:
In suffix u, selected from unsigned int, unsigned long, unsigned long long as the smallest data type;
at least l suffix long, unsigned long from the suffix to ll and selecting long long;
float literal suffix f to a float to a long double suffix l;

List initialization:
int I = 0;
int I = {0}; // being given loss of accuracy will be present
int i {0}; // being given loss of accuracy will be present
int i (0); // not given

Declarations and definitions:
Variables can be declared many times, it can only be defined once.

extern int i;   //声明,用于使用别处变量
extern int i=1;  //声明并定义
int j;  //声明并定义

Note that when the complex type definition of space:

int* p, p2;  //定义p为指针类型,p2为int, 写法不妥
int *p, *p2;

Pointer:
initialize all pointers to avoid errors can not be estimated.

生成空指针
int *p = nullptr;
int *p = 0;
int *p = NULL;   //需要cstdlib,避免使用

Any non-zero values are pointers condition is true.
void * pointer type can store any type of address, but can not access the object, because they do not know the type of object.

Published 558 original articles · won praise 500 · Views 1.53 million +

Guess you like

Origin blog.csdn.net/qq_16234613/article/details/104089360