gpt4 book ai didi

C 指针 : how to say this code

转载 作者:太空宇宙 更新时间:2023-11-04 05:03:53 27 4
gpt4 key购买 nike

我发现这个页面对指针的解释如下:
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] */

但是,“y 现在是 1”“x 现在是 0” 行描述的是结果,而不是代码。如何“说”这些行来描述代码(就像其他行一样)?

换句话说,“y is now 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" */

或者,为了更贴近您的原始评论:

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] */

免责声明

我实际上不会将这样的注释写入代码。代码注释用于解释基本原理;代码语法应该是不言自明的。

我的意思是,如果出于像您这样的目的而必须这样做的话,我会像那样注释代码。

关于C 指针 : how to say this code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7017803/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com