OK, this is my first poll. I'd like to know how you declare pointers. I'll start. I use:
char* name;
I put the * next to the type mainly to make clear that it's not the defference (sp?) operator.
How about you?
Printable View
OK, this is my first poll. I'd like to know how you declare pointers. I'll start. I use:
char* name;
I put the * next to the type mainly to make clear that it's not the defference (sp?) operator.
How about you?
When you haveit looks as if both a and b is of type char*, but actually b is only of type char. To avoid confusion, rather useCode:char* a,b;
to more clearly show what you meanCode:char *a, b;
char *something;
Always...
type* pVariableName;
... and one declaration per line - no confusion.
I used to use
Type *variable;
but i've heard it's better to use
Type* variable;
Plus, it makes more sense in many cases. I've been trying to change my habits towards the latter, but now and again I find myself typing Type *var.
Well maybe I should change my habits as well.....any idea why this way char* var; might be better?
i've heard that 'type *var' is better, because you're only making that variable a pointer, not everything in that decliration, so it makes more sense to keep the * with the single variable. makes sense to me.. it's what i've always used.
I use
:DCode:std::string name;
Seriously, I think char* name looks best and I never declare pointers and non-pointers on the same line anyway.
Purely asthetics, but I always place the asterisk between the type and variable:
const char * str;
void Foo(int * x);
...etc...
That's the best practice.Quote:
...and I never declare pointers and non-pointers on the same line anyway.
I usually use char *pointer. But once in a while there comes a time that I need to use char* pointer.
I never include non-pointers and pointers on same line either.
It really depends on you... since they are all correct, just choose what's more suitable to you...
I prefere char *
char * duh;
//i'll do multiple decl's of anything but pointers
int a,b,c,d,e;
bool go,stop,rewind;
float * info;
float * theNum;
I usually use
char* pointer
because the * makes it a separate datatype. Putting it adjacent to char makes the type information close together and separate from the variable name.
For multiple line declarations I usually do something like this:
Code:char Data,
* Pointer;
char* always;
for clarity if i have a char and a char* i put them on seperate lines
char* p,* q;
char c, ch;
No difference between the two. But for the sake of declaring multiple pointers in one line, I use the *var method.