'int * i'或'int * i' [英] 'int *i ' or 'int* i'

查看:86
本文介绍了'int * i'或'int * i'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那里,

在C编程中,对于指针,我看到了两种编程风格:

一个用变量连接''*'' ,比如''int * i'';

另一个是用数据类型连接''*'',''int * i''


我想知道哪种风格更标准。是否有规则要遵循?


提前致谢,

Julia

Hi, there,

In C programming, for pointer, I saw two programming styles:
one is connecting ''*'' with variable, like, ''int *i'';
the other is connecting ''*'' with data type, like, ''int* i''

I wonder which style is more standard. Is there a rule to follow?

Thanks in advance,

Julia

推荐答案

Julia写道:
Julia wrote:

>

那里,


在C编程中,对于指针,我看到了两种编程风格:

一个是用变量连接''*'',比如''int * i'';

另一个用数据类型连接''*'',''int * i''


我想知道哪种风格更标准。
>
Hi, there,

In C programming, for pointer, I saw two programming styles:
one is connecting ''*'' with variable, like, ''int *i'';
the other is connecting ''*'' with data type, like, ''int* i''

I wonder which style is more standard.



我认为

int * i;


$ b $更常见b int * i;


int * i;

伴随着

int * i,* j,* k;

I think that
int *i;
is more common than
int* i;

int *i;
goes along with
int *i, *j, *k;


是否有规则要遵循?
Is there a rule to follow?



-

pete

--
pete


2006-07-21,Julia < ju ******** @ yahoo.comwrote:
On 2006-07-21, Julia <ju********@yahoo.comwrote:

那里,


在C中编程,对于指针,我看到了两种编程风格:

一个用变量连接''*'',比如''int * i'';

另一个将''*''与数据类型连接起来,比如''int * i''
Hi, there,

In C programming, for pointer, I saw two programming styles:
one is connecting ''*'' with variable, like, ''int *i'';
the other is connecting ''*'' with data type, like, ''int* i''



int *我的风格更好,恕我直言。


你怎么认为

int * i,j,k,l;

是什么意思?您认为设计师的意图是什么意思?

int * a,* b,c,* d;

的含义非常明显,尽管有些将争论声明组合成一行将讨论

的优点。

int *i is better style, IMHO.

What do you think that
int* i, j, k, l;
means? What do you think that the designer intended it to mean?
int *a, *b, c, *d;
is very obvious in what it means, although some will debate the
merits of comining declarations onto one line.


我想知道哪种风格更标准。是否有规则要遵循?
I wonder which style is more standard. Is there a rule to follow?



风格没有标准化,任何试图这样做的人都会被哄骗。它押韵! ;-)


-

Andrew Poelstra<网站关闭>

我的服务器已关闭;你不能给我发邮件,也不能随便发帖。

Style isn''t standardized, and anyone attempting to do so would be
ostricized. It rhymes! ;-)

--
Andrew Poelstra <website down>
My server is down; you can''t mail
me, nor can I post convieniently.


" Julia" < ju ******** @ yahoo.comwrites:
"Julia" <ju********@yahoo.comwrites:

在C编程中,对于指针,我看到了两种编程风格:

一个用变量连接''*'',比如''int * i'';

另一个用数据类型连接''*'',''int *我'


我想知道哪种风格更标准。有规则要遵循吗?
In C programming, for pointer, I saw two programming styles:
one is connecting ''*'' with variable, like, ''int *i'';
the other is connecting ''*'' with data type, like, ''int* i''

I wonder which style is more standard. Is there a rule to follow?



两者在语义上都是相同的;编译器不关心你使用哪一个b $ b。但是int * i;形式更紧密地跟随

声明的实际含义。


C使用声明跟随使用原则,这可能会让你感到困惑

,直到你习惯它为止。例如,


int * i;


表示* i是一个int,而不是i是指向int的指针 ;。 (实际上它意味着

两者,因为它们在逻辑上是等价的,但是* i是一个int

解释是与语法相对应的解释。 )


当你在一行上声明多个东西

时,这一点变得尤为重要。例如:


int x,* y,** z;


表示x,* y和** z都是类型为int(使x为int,y

a指向int的指针,za指向指向int的指针)。


使用


int * x;


很容易写:


int * x,y;


,它不会使x和y指向int;它使xa指向

int和y为int,因为你可以看到你是否更正了间距:


int * x,y;


由于令牌之间的空格被忽略,如果您的布局具有误导性,编译器不会警告您/ b
;它只是假设你的意思是你写的是什么。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

Both are semantically identical by themselves; the compiler doesn''t
care which one you use. But the "int *i;" form more closely follows
the actual meaning of the declaration.

C uses a "declaration follows use" principle, which can be confusing
until you get used to it. For example,

int *i;

means "*i is an int", not "i is a pointer to int". (Actually it means
both, since they''re logically equivalent, but the "*i is an int"
interpretation is the one that corresponds to the syntax.)

This becomes particularly important when you declare multiple things
on one line. For example:

int x, *y, **z;

means that x, *y, and **z are all of type int (which makes x an int, y
a pointer to int, and z a pointer to pointer to int).

Using

int* x;

makes it tempting to write:

int* x, y;

which doesn''t make x and y pointers to int; it makes x a pointer to
int and y an int, as you can see if you correct the spacing:

int *x, y;

And since spaces between tokens are ignored, the compiler won''t warn
you if your layout is misleading; it will simply assume that you meant
what you wrote.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于'int * i'或'int * i'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆