Ç - 指针初始化,星号位置 [英] C - initialization of pointers, asterisk position

查看:77
本文介绍了Ç - 指针初始化,星号位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/180401/pointer-declarations-in-c-placement-of-the-asterisk\">Pointer声明在C ++:星号的位置


什么是把星号的最恰当的方法是什么?为什么呢?

  1)型*变种;
2)型*变种;


解决方案

没关系,只要你只能声明一个指针,它通常是这样写在第二个例子(在codeI通常读/写),但编译器是一样的。

麻烦的可以出来,如果​​你宣布一个以上的指针,例如这不是声明两个指针,而是声明了一个指针和类类型的一个变种:)

 键入* VAR1,VAR2;

您需要做的,而不是:

 键入* VAR1,* VAR2;

我preFER由VAR传真使用*。

Possible Duplicate:
Pointer declarations in C++: placement of the asterisk

What is the most proper way to place asterisk? Why?

1)    type*     var;
2)    type      *var;

解决方案

It does not matter as far as you are declaring only one pointer, it is usually write like in the second example (in the code i usually read/write) but for the compiler is same.

The trouble can come out if you are declaring more than one pointer, for example this is not declaring two pointer, instead it declares one pointer and one var of type type :)

type* var1, var2;

You need to do instead:

type* var1, *var2;

I prefer to use the * by the var allways.

这篇关于Ç - 指针初始化,星号位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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