zoukankan      html  css  js  c++  java
  • C/C++变量命名规则

    转载自:https://blog.csdn.net/hrw0702/article/details/5563699#commentBox

    一、变量命名规范

    变量体如果是多个单词,每个单词的首字母大写。

    int iStudentAge;  

    使用变量前缀

    1、整型前缀

    short sValue;   // s为short的前缀  
      
    int iAge;       // i为int的前缀  
      
    unsigned int uiAge;   // ui为unsigned int的前缀(两个单词的首字母)  
      
    long lValue;     // i为long的前缀 

    2、浮点前缀

    float fScore;     // f为float的前缀  
      
    double dValue;       // d为double的前缀 

    3、字符型前缀

    char cChar;         // c为char的前缀  
      
    TCHAR tcChar      // 多字节字符和Unicode字符兼容类型的前缀tc  
      
    wchar_t  wcChar    // 宽字符前缀wc  

    4、字符串前缀

    char szName[30];    // sz为C语言字符串的前缀  
      
    string strName;      // str为C++字符串变量的前缀  
      
    CString strInfo;     // str为MFC字符串变量的前缀  

    5、布尔前缀

    bool bPass;         // b为bool的前缀  

    6、指针前缀

    int * pValue;       //p为指针的前缀  

    说明:由于指针是指向一定数据类型的变量,因此p后面要不要再加一个前缀一直让我举棋不定。如果再加上前缀比如:int * piKey;        char * pszInfo;  

    这样似乎意义更完整,但势必会增加变量的字符长度。因此,这里就不硬性规定了。但是,指正变量以p开头应该是雷也打不动的。

    7、数组的前缀

    int arrNum[10];  // arr为数组的前缀  

    说明:和指针变量一样,arr后是否再加数组元素的数据类型前缀取决于你自己。 

    8、 全局变量

    int  g_iNums;  

    说明:全局变量一律以g_开头,后面为变量体,变量体依然要有前缀。

    二、函数命名规范

    大驼峰式命名。函数名称由单词组成,每个单词的首字母都要大写。

    比如:

    void FirstPage();
    void TestSpace();

    void ShowBackgroud();
    void DrawSnake();
    void SnakeMove();
  • 相关阅读:
    陶瓷电容的结构、工艺、失效模式
    Vue.js最佳实践
    Vue 超快速学习
    CSS 小技巧
    HTML5 Canvas
    webkit下面的CSS设置滚动条
    Some untracked working tree files would be overwritten by checkout. Please move or remove them before you can checkout. View them
    JSCS: Please specify path to 'JSCS' package
    React中ref的使用方法
    React 60S倒计时
  • 原文地址:https://www.cnblogs.com/FengZeng666/p/9695048.html
Copyright © 2011-2022 走看看