0

why use pointers

15th Jun 2017, 8:14 AM
Saikumar Neelisetty
Saikumar Neelisetty - avatar
3 odpowiedzi
+ 17
You can use it to DIRECTLY edit the value of an original variable passed by reference to a function without returning an edited copy or any other workarounds (...Regardless the scope...) ....
15th Jun 2017, 8:20 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
basically pointers point your variable, and contain variable address. int a=5, p *p=&a; cout<<p; cout<<&a; cout<<a;
15th Jun 2017, 3:11 PM
meherDev
meherDev - avatar
+ 1
Because by default, if you call a function with an argument from another function, that argument WILL GET copied rather than passing a reference. Needless ro say, if you work with huge classes and structs (or arrays with 1000+ elements) the copying could take more time than the function it self. Not to mention that everything you do to that passed parameter will NOT be saved to the original (hence the copy). On the other hand if you pass it with a pointer you are effectively working with the original array/class.
16th Jun 2017, 7:33 AM
Norbivar
Norbivar - avatar