2018/2/9 The first day of the winter holiday in my hometown.Review c++ and record attention points.
1.enum
#include <iostream>
using namespace std;
enum time
{
first,second,
third,forth,fifth
};
int main()
{
enum time a=fifth;
if (a==fifth)
{
cout << a;
}
return 0;
}
2.自动类型转换
#include <iostream>
using namespace std;
int main()
{
int a=-10;
unsigned int b=1;
std::cout << a+b<<endl;;
return 0;
}
result:4294967287
3.全局变量和局部变量
#include <iostream>
using namespace std;
// 全局变量声明
int g = 20;
int fun1(int a,int b){
g=a+b;
cout<<"被改变的全局变量为:"<<g<<endl;
return 0;
}
int fun2(){
cout<<"此时的全局变量为:"<<g<<endl;
return 0;
}
int main(){
fun2();
fun1(10,20);
fun2();
return 0;
}
result:此时的全局变量为:20
被改变的全局变量为:30
此时的全局变量为:30
4 宏定义 #define 和常量 const 的区别
void f1 ()
{
#define N 12
const int n 12;
}
void f2 ()
{
cout<<N <<endl; //正确,N已经定义过,不受定义域限制
cout<<n <<endl; //错误,n定义域只在f1函数中
}
void f1()
{
#define N 12
const int n = 12;
#undef N //取消宏定义后,即使在f1函数中,N也无效了
#define N 21//取消后可以重新定义
}
5 volatile & restrict
volatile:每次调用都去内存当中读取;
restrict : 由 restrict 修饰的指针是唯一一种访问它所指向的对象的方式;
6 张飞博客的两张图,理解#include和extern在工程项目中的用法