• c++学习笔记4:如何写好注释


    1.单行注释一般放在语句的上方:

    // cout and endl live in the iostream library
    std::cout << "Hello world!" << std::endl;

    2.多行注释写法:

    /* This is a multi-line comment.
     * the matching asterisks to the left
     * can make this easier to read
     */

    3.注释的用处

    .At the library, program, or function level, describe what
    .Inside the library, program, or function, describe how
    .At the statement level, describe why

    通俗点就是:

    (1)描述该块代码是什么;

    (2)描述该块代码如何实现;

    (3)描述该块代码为什么要如此实现;

    接下来举些例子:

    (1)what

    // This program calculate the student's final grade based on his test and homework scores.

    (2)how

    /* To calculate the final grade, we sum all the weighted midterm and homework scores
        and then divide by the number of scores to assign a percentage.  This percentage is
        used to calculate a letter grade. 
    */
    // To generate a random item, we're going to do the following:
    // 1) Put all of the items of the desired rarity on a list
    // 2) Calculate a probability for each item based on level and weight factor
    // 3) Choose a random number
    // 4) Figure out which item that 

    (3)why

    // We need to divide items by 2 here because they are bought in pairs
    cost = items / 2 * storePrice;
    怕什么真理无穷,进一寸有一寸的欢喜。---胡适
  • 相关阅读:
    1065-两路合并
    1064-快速排序
    1063-冒泡排序
    1062-直接插入排序
    1061-简单选择排序
    1058-Tom and Jerry
    关于WinForm引用WPF窗体
    ref与out的区别
    看到他我一下子就悟了(续)---委托
    域名的a记录转过来他的公网ip
  • 原文地址:https://www.cnblogs.com/hujianglang/p/6120295.html
Copyright © 2020-2023  润新知