Oh the joys of being a memory management noob !
I'm getting bit by some Objective-C code, eventhough I understand the basics of pointers, I've seen these two different constructs, without being able to really understand their difference.
Can anyone enlighten me ?
Edited my question, the constructs didn't behave differently, instead I got bit yet again by the multiple declarations gotcha. Thanks !
There’s no difference – it’s a matter of taste. However, beware that the pointer actually always binds to the name, not the type. So this:
Type* var1, var2;
Declares var1 as a pointer to Type, while var2 is not a pointer. That’s just one more reason not to declare multiple variables in the same statement.
Historically, the Type *var notation is more common in C, where it is read as “var is declared as a pointer to Type”, i.e. “the type of *var is Type”. In C++, on the other hand, Type* var is more common and is read as “var is declared as being of type ‘pointer to Type’”.
There is no difference at all.
But consider the following line:
Type* var1, var2;
Here only var1 is a pointer to Type, but it is easier to see that if you write
Type *var1, var2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With