• 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: 如果觉得本文对你有帮助的话,那么【推荐】给大家吧,希望今后能够为大家带来更好的技术文章!敬请【关注】
  • 相关阅读:
    「BZOJ1954」Pku3764 The xor – longest Path
    【bzoj4260】【Codechef REBXOR】
    BZOJ_3012_[Usaco2012 Dec]First!
    【bzoj1174】[Balkan2007]Toponyms
    String
    前缀和
    [POI2008] CLO
    [Scoi2010] 游戏
    CodeForces892E
    并查集的删除操作
  • 原文地址:https://www.cnblogs.com/hellogiser/p/define-typedef-const.html
Copyright © 2020-2023  润新知