pointer question
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*)).
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*)).
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:
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.
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
Popular Topics
Advertisement