Dynamic memory and pointer question

Is there any reason to use pointers if you dont use dynamic memory?

I mean... i dont see any good reason of using pointers to point to a regular variable.
If you want to pass Pointers are a good idea for example if you want to pass an object to a function. If you pass by value rather than pass a pointer to the function, it will use more memory (a copy of the variable will be created for that function). Hopefully that makes sense (and hopefully it is correct :p ).
hmm yes, but if i wanted to pass an object through a function, then i would pass my reference.

At this moment, i cant see any reason to make an object, then make a pointer and point to that object if you can make a pointer and use the "new" keyword, without pointing to a regular object.
Last edited on
Also, pointers are needed for polymorphism.
ahh yes. good point :)
Also, pointers are needed for polymorphism.

References work fine for polymorphism.

In general, it's good practice to prefer not to use pointers, if only for the reason that they give you more opportunity to screw up. There are, nevertheless, things that you cannot accomplish without them. Try implementing a linked list with references, for instance.
Topic archived. No new replies allowed.