我发现这个页面有以下指针解释:http:
//www.woyouxian.net/c/c0501.html
int x = 1, y = 2, z[10];
int *ip; /* ip is a pointer to int */
ip = &x; /* ip now points to x */
y = *ip; /* y is now 1 */
*ip = 0; /* x is now 0 */
ip = &z[0]; /* ip now points to z[0] */
Run Code Online (Sandbox Code Playgroud)
但是,行"y现在是1"而"x现在是0"描述了结果,而不是代码.如何"说"那些线来描述代码(如其他线那样)?
换句话说,行"y现在为1"并不隐含地在行上具有文字"1",因此描述描述了代码的结果而不是代码本身.我想要一个代码本身的描述.
C不是口语,所以这里的意见会有很大不同.
我会这样说并评论:
int x = 1, y = 2, z[10];
int *ip; /* declares a pointer-to-int called "ip" */
ip = &x; /* makes "ip" point to "x" */
y = *ip; /* sets "y" to the value of what "ip" points to, i.e. 1 */
*ip = 0; /* sets the value of what "ip" points to to 0 */
ip = &z[0]; /* makes "ip" point to the first element in the array "z" */
Run Code Online (Sandbox Code Playgroud)
或者,更接近原始评论:
int x = 1, y = 2, z[10];
int *ip; /* ip is a pointer to int */
ip = &x; /* ip now points to x */
y = *ip; /* y's value is now equal to the value of the object that "ip" points to */
*ip = 0; /* the value of the object that "ip" points is now 0 */
ip = &z[0]; /* ip now points to z[0] */
Run Code Online (Sandbox Code Playgroud)
我实际上不会将这样的注释写入代码中.代码注释用于解释理由 ; 代码语法应该是不言自明的.
我的意思是,如果我不得不为了像你这样的目的,我会对代码进行注释.
| 归档时间: |
|
| 查看次数: |
194 次 |
| 最近记录: |