Skip to main content
gamedev.net
🔒 Locked

pointer question

Started by daniel_i_l 4 replies 950+ views
Original Post
daniel_i_l
daniel_i_l
Whats the difference between: int* pointer; and int *pointer; Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
bakery2k1
bakery2k1
None. In C++, whitespace is pretty much insignificant.
cignox1
cignox1
None, but try to keep a consistent style:
int* a, b;
wont declare 2 variables of type pointer to int, but a pointer to int and an int.
You should write
int* a, *b;
to get that. But then you can as well write:
int *a, *b;

The 'problem' is that sometimes the "*" applies to the int as in casting (where you write (int*)).
kuphryn
kuphryn
x *y better easy recognize data type

Kuphryn
Zahlman
Zahlman
Quote:
Original post by kuphryn
x *y better easy recognize data type

Kuphryn


... but 'x*' is the data type. What are you talking about?

Anyway, here's what good ol' BS (Bjarne Stroustrup!) has to say about it.
Xai
Xai
My style, no better of worse than others, but just for you to take as 1 available suggestion:

int main(void)  {  }int* foo(int *x, int *y, int &z, const int &zee)  {  int i, j, k;  int *a;  int *b;  int *c;  }


so basically I use the (*) attaches to variable name syntax, except in the case of the function declaration there is no variable name, so I use (*) attached to return type.

I also don't declare mutliple poitners on one line unless writing an algorithm which is nothing but pointer arithmatic, even though my style is the one that would work fine if I did multi-declare. Just personal preference and habit.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.