+ 9

Dot . Vs Arrow Access ->..?

Both can be used to access member of a User Defined DataType but why should we even bother to use -> instead of .(dot operator) ...I mean we have to create a pointer of that data type...store the address of the object then we can use the -> Why use -> instead of dot operator ...

27th Jan 2018, 9:37 AM
Cyberspace Cyborg
Cyberspace Cyborg - avatar
2 Answers
+ 2
Often you don't want to pass a copy of a structure around, but rather a reference to an existing structure. That's only possible using a pointer. If you'd create a "normal" struct from a pointer again just to be able to use the dot operator (Foo bar = *baz) you will have a copy of the structure again and you won't actually modify the fields of the original structure. So the arrow operator is incredibly useful for saving memory by avoiding copies and modifying existing data in other functions.
27th Jan 2018, 10:04 AM
SplittyDev
SplittyDev - avatar