Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

int *p vs int* p

77 views
Skip to first unread message

David Xingliang Lou (CS 137 Tutor)

unread,
Nov 5, 2010, 1:42:17 PM11/5/10
to
Do you have a strong preference towards either int *p or int* p?

http://www.student.cs.uwaterloo.ca/~cs137/current/res/intstarp.shtml

Rob Schluntz (CS241 Tutor)

unread,
Nov 29, 2010, 2:30:02 PM11/29/10
to
David Xingliang Lou (CS 137 Tutor) wrote:
> Do you have a strong preference towards either int *p or int* p?
>
> http://www.student.cs.uwaterloo.ca/~cs137/current/res/intstarp.shtml

I have a preference towards int* p. This is because (int*) is a type: an
integer pointer, with a variable named p. On the other hand, "int *p"
reads "type: integer", with a pointer to a variable: p. Here int* is a
type, the type isn't just int. Same as if you had (char* c), which would
be a pointer to a character, not (char *c): a pure character type.

</devil's advocate>

David Xingliang Lou (CS 137 Tutor)

unread,
Nov 29, 2010, 3:16:36 PM11/29/10
to

Let me try to understand your argument.

So you said, because the type of p is an integer pointer, we should
naturally group the type name (int*) as a single entity. A declaration
like (int *p) groups the variable name and part of the type name
together, which looks weird. Am I understanding you correctly?

Then, Rob, let me ask you this. What is the type of the foo:

int *(*(*foo[4])(int x, int y))[5];

The type of foo is (int *(*(*[4])(int,int))[5]) (an array of pointers to
functions that takes 2 integer parameters, and returns a pointer to an
array of pointers to integers), but notice that you don't just say

int *(*(*[4])(int,int))[5] foo; //syntax error

You DON'T put the variable name at the end (like you do when you say
int* p), you put it in the MIDDLE, around the stars and brackets. This
is how variables are declared in C. This is how the compiler read them.
(int *p) is consistent with this idea.

What do you have to say to that, Rob? :)

dkho...@gmail.com

unread,
Jul 26, 2013, 7:44:05 PM7/26/13
to
On Friday, November 5, 2010 10:42:17 AM UTC-7, David Xingliang Lou (CS 137 Tutor) wrote:
> Do you have a strong preference towards either int *p or int* p?
>
> http://www.student.cs.uwaterloo.ca/~cs137/current/res/intstarp.shtml



fgmdhgkdfgdsks
ghlfdlk
gfdfk
ghhg
hgfhfkg djbfaef vds
0 new messages