C ++中的int * x和int * x之间有区别吗? [英] Is there a difference between int *x and int* x in C++?

查看:262
本文介绍了C ++中的int * x和int * x之间有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将回到我的C ++学习中,并真正地试图理解基础知识.指针总是给我带来麻烦,我想确保在继续前进并迷路之前,我能真正做到这一点.

I'm getting back into my C++ studies, and really trying to understand the basics. Pointers have always given me trouble, and I want to make sure I really get it before I carry on and get confused down the road.

可悲的是,我一开始就因我正在阅读的教程不一致而陷入困境.有些人以这种方式进行指针声明:

Sadly, I've been stymied at the very outset by an inconsistency in the tutorials I'm reading. Some do pointer declarations this way:

int *x

有些方法是这样的:

int* x

现在,两者中的前者似乎是最常见的.这让我很沮丧,因为第二点对我来说意义更大.当我读int * x时,我读到这里是一个int,它的名字是* x",这不太正确.但是,当我阅读第二篇文章时,我看到这是一个int指针,它的名称是x",这很准确.

Now the former of the two seems to be by far the most common. Which is upsetting, because the second makes much more sense to me. When I read int *x, I read "Here is an int, and its name is *x", which isn't quite right. But when I read the second, I see "here is an int pointer, and its name is x", which is pretty accurate.

因此,在构建自己的思维导图之前,两者之间在功能上有区别吗?如果我第二种方式做,我会成为麻风病人吗?

So, before I build my own mental map, is there a functional difference between the two? Am I going to be a leper outcast if I do it the second way?

谢谢.

推荐答案

著名的 Bjarne Stroustrup ,以创建和开发C ++而著称,...

The famous Bjarne Stroustrup, notable for the creation and the development of the C++, said ...

在"int * p;"之间进行选择和"int * p;"与权利无关 错了,但是关于风格和强调. C强调表达; 声明常常被认为仅仅是一种必要的邪恶. 另一方面,C ++非常重视类型.

The choice between "int* p;" and "int *p;" is not about right and wrong, but about style and emphasis. C emphasized expressions; declarations were often considered little more than a necessary evil. C++, on the other hand, has a heavy emphasis on types.

典型的C程序员"写"int * p;".并解释说"* p是什么 是"int"强调语法,并且可能指向C(和C ++) 声明语法,以证明样式的正确性.的确, *绑定到语法中的名称p.

A "typical C programmer" writes "int *p;" and explains it "*p is what is the int" emphasizing syntax, and may point to the C (and C++) declaration grammar to argue for the correctness of the style. Indeed, the * binds to the name p in the grammar.

典型的C ++程序员"写"int * p;".并解释说"p是一个 指向int的指针"强调类型.确实p的类型是int *. 显然更喜欢这种强调,并认为它对于使用 C ++的更多高级部分.

A "typical C++ programmer" writes "int* p;" and explains it "p is a pointer to an int" emphasizing type. Indeed the type of p is int*. I clearly prefer that emphasis and see it as important for using the more advanced parts of C++ well.

因此,没有区别.这只是一种代码样式.

So, there's no difference. It is just a code style.

此处

这篇关于C ++中的int * x和int * x之间有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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