在C语言中,为什么星号在变量名称之前,而不是之后的类型? [英] In C, why is the asterisk before the variable name, rather than after the type?

查看:894
本文介绍了在C语言中,为什么星号在变量名称之前,而不是之后的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么大多数C程序员名字的变量是这样的:

Why do most C programmers name variables like this:

int *myVariable;

而不是这样的:

int* myVariable;

两者都是有效的。在我看来,该星号是类型,变量名不是一个部分的一部分。任何人能解释这个逻辑?

Both are valid. It seems to me that the asterisk is a part of the type, not a part of the variable name. Can anyone explain this logic?

推荐答案

他们是完全等价的。
然而,在

They are EXACTLY equivalent. However, in

int *myVariable, myVariable2;

很明显,MYVARIABLE有键入为int * ,而myVariable2有类型的内部即可。

It seems obvious that myVariable has type int*, while myVariable2 has type int. In

int* myVariable, myVariable2;

似乎很明显,两者都键入为int * ,但myVariable2没有这种类型的。

it seems obvious that both are of type int*, but myVariable2 does NOT have this type.

因此​​,第一编程风格更加直观。

Therefore, the first programming style is more intuitive.

这篇关于在C语言中,为什么星号在变量名称之前,而不是之后的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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