问题描述
在C ++中,下面的意思是为int指针分配内存:
in C++, the following means "allocate memory for an int pointer":
int* number;
所以,星号是变量类型的一部分;没有它,这将意味着别的东西(这就是为什么我通常不分离星号和变量类型)。那么什么原因星号被认为是别的东西,而不是类型的一部分?例如,看起来更好,如果下面的意思是为两个int指针分配内存:
So, the asterisk is part of the variable type; without it, that would mean something else (that's why I usually don't separate the asterisk from the variable type). Then what is the reason the asterisk is considered something else, instead of being part of the type? For example, it seems better, if the following meant "allocate memory for two int pointers":
int* number1, number2;
我错了吗?
推荐答案
Stroustrup被问及他说(释义)
Stroustrup was asked this and he said (paraphrasing)
只要你永远不会在同一行上声明两个
ponters,你就会这么想。
You can think however you like, as long as you never declare two ponters on the same line.
适用于我。我是一个员工* pE
的人,但我结婚了员工* pE
- 我的建议不会太忙了。
Works for me. I'm an Employee* pE
kind of person, but I'm married to an Employee *pE
kind of person - my advice would be not to get too worked up about it.
这篇关于类型声明 - 指针星号位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!