尽量使用括号
简洁写法
while((i = get_value())!=42)
条件运算符
condition ? answer1:answer2;
finalgrade = (grade > 90)? "high":(grade < 60)?"false":"pass";
显示转换
1.static_cast
不包含底层const都能进行类型转换
int i,j;
double slop = static_cast<double>(j) / i;
还可转换void指针类型,但是类型必须一致
void *p = &d;
double *dp = static_cast<double*>(p);
2.const_cast
改变底层const
const char *pc;
char *p = const_cast<char*>(pc);
3. reinterpret_cast
不同类型的指针之间、不同类型的引用之间以及指针和能容纳指针的整数类型之间的转换
极具危险性
int *ip;
char *pc = reinterpret_cast<char*> ip;
string str(pc);//Wrong