pointer question

Started by
4 comments, last by Xai 18 years ago
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
Advertisement
None. In C++, whitespace is pretty much insignificant.
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*)).
x *y better easy recognize data type

Kuphryn
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.
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.

This topic is closed to new replies.

Advertisement