码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-12-01 03:54:46      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:blog   ram   单行注释   idt   dom   library   cti   为什么   ice   

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;

 

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

标签:blog   ram   单行注释   idt   dom   library   cti   为什么   ice   

原文地址:http://www.cnblogs.com/hujianglang/p/6120295.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!