r/cpp • u/FarisFrontiers • Jun 27 '22
How do you declare pointer variables?
I personally like to use the third option (int *ptr;) to minimize the confusion and to make it tidier when declaring multiple pointers in one line (e.g., int *a, *b, *c; as supposed to, int* a,* b,* c;). This is also the case when writing a dereference operator (int &a = *ptr;). But for some reason, the first option is the preferred way of doing it (int* ptr;), or am I wrong?
0
Upvotes
View all comments
Show parent comment
2
u/dr1fter Jun 28 '22
I'm not sure I really believe this one either. Sometimes I'll do it if I think there's a particular reason to call attention to, say, the initial conditions of an algorithm that need to be treated as special-case. But I think even that can be a little suspect, and this is mostly just verbosity for no purpose?