c++回顾(一)

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在工程项目中的用法
这里写图片描述

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值