
1 timonwong 2013-09-26 08:50:56 +08:00 我的习惯 变量声明放右边: int *p1, *p2, *p3; 返回值放中间: int * test() |
2 jedyu 2013-09-26 08:51:35 +08:00 int *p = NULL; int* test(); |
3 iLluSioN 2013-09-26 08:53:00 +08:00 为了避免类似的纠结,常年放中间。。。 |
4 GordianZ 2013-09-26 08:57:12 +08:00 放右边,好区别下面两种: int *p1, *p2, *p3; int* p1, p2, p3 |
6 yujnln 2013-09-26 09:01:03 +08:00 1. int* p; // legal but might be misleading We say that this definition might be misleading because it suggests that int* is the type of each variable declared in that statement. Despite appearances, the base type of this declaration is int, not int*. The * modifies the type of p. 2. int* test(); // func returns a pointer to int |
&nbp; 7 angelface 2013-09-26 09:03:14 +08:00 这个没有定论放在哪边好, 大牛们也是各有各的写法,但我倾向说放左边,这样从语音上比较合理 int* p;一个指向int型的指针p,放在右边像是在取值。 |
8 xdeng 2013-09-26 09:04:18 +08:00 我有变量名的 习惯放右边 没得放左边 |
9 sinxccc 2013-09-26 09:10:49 +08:00 放中间或者放右边,放左边太容易歧义了,星号不是用来修饰类型,而是用来修饰变量的。 |
10 jiangtao92 2013-09-26 10:07:39 +08:00 其实放在左边也是会出现歧义,以为int* 是一个类型,例如 int* a,b; a 是指针,b 还是int。。 |
11 julyclyde 2013-09-26 13:15:46 +08:00 从语法上应该是 int *p, i; 声明一个p指针和i变量 从语义上讲,p指向一个int,所以int修饰的是*p |