zoukankan      html  css  js  c++  java
  • c++关键字之#define typedef const

    【#define】

    #define是预处理指令,在编译预处理时进行简单的替换,不作正确性检查。

    【typedef】

    typedef只是为了增加可读性而为标识符另起的新名称

    在自己的作用域内给一个已经存在的类型一个别名。

     C++ Code 
    1
    2
    3
    4
    5
     
    typedef int *int_ptr;
    #define INT_PTR int*

    int_ptr a, b; 
    // int *a,*b;
    INT_PTR a, b; // int *a,b;

     【const】

     C++ Code 
    1
    2
    3
    4
    5
     
    const int *p; // *p is const
    int const *p; // *p is const

    int *const p; // p is const
    const int *const p;  // *p and p are both const

    const在*左边,*p是一个整体,不可改变;const在*右边,p是一个整体,不可改变。

    【#define-typedef-const】

     C++ Code 
    1
    2
     
    const int_ptr p; // ===>int* const p;   (p is const)
    const INT_PTR p; // ===>const int *p;   (*p is const)

    个人学习笔记,欢迎拍砖!---by hellogiser

    Author: hellogiser
    Warning: 本文版权归作者和博客园共有,欢迎转载,但请保留此段声明,且在文章页面明显位置给出原文连接。Thanks!
    Me: 如果觉得本文对你有帮助的话,那么【推荐】给大家吧,希望今后能够为大家带来更好的技术文章!敬请【关注】
  • 相关阅读:
    jQuery序列化
    jQuery的ajax与django传参
    Django中的cookie与session操作
    Django文件上传
    Django表单的简单应用
    django加载模板文件
    django-admin.py创建项目失败解决方法
    django笔记
    unity创建xml与加载xml
    JavaScript相关
  • 原文地址:https://www.cnblogs.com/hellogiser/p/define-typedef-const.html
Copyright © 2011-2022 走看看