凡把明星C和C ++指针符号 [英] Where to put the star in C and C++ pointer notation

查看:109
本文介绍了凡把明星C和C ++指针符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/6990726/correct-way-of-declaring-pointer-variables-in-c-c\">Correct用C声明指针变量的方式/ C ++

有关一段时间以下一直烦我,我应该在哪里把明星在我的指针符号。

For some time the following has been annoying me, where should I put the star in my pointer notation.

int *var; // 1

int* var; // 2

显然做同样的事情,两个符号是正确的,但我发现大多数文献和code我期待在使用的第1符号。

obviously do the same thing, and both notations are correct, but I find that most literature and code I look at use the 1th notation.

会不会更正确使用二路符号,用空格分开的类型和变量名,而不是混合的类型和令牌变量?

wouldn't it be more 'correct' to use the 2th notation, separating the type and the variable name by a whitespace, rather than mixing the type and variable tokens?

推荐答案

没有。决不。 &LT; G&GT;

但考虑:

int* var1, var2;

在这里,安置 * 是一种误导,因为它的不可以适用于 VAR2 ,这是一个 INT 而不是为int *

Here, the placement of the * is misleading, because it does not apply to var2, which is an int and not an int*.

这篇关于凡把明星C和C ++指针符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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