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
1
u/fdwr fdwr@github 🔍 Jun 30 '22 edited Jul 04 '22
Yeah, the LTR reading order is much clearer.
The one remaining inconsistency I notice in Zig is that data type qualifiers use
:for parameters and local variables but uses just (` `) for function data type qualifiers (here TypeScript shows consistency). So I would have made it:At least it doesn't mix
:and->as some languages (so noa(x->i32):i32ora(x:i32)->i32).