   When to use pointers?
  Are there any rules of thumb on whether or not to use a pointer? Should pointers only be used when you want to pass objects through a function AND copy them to another one?Thanks   
  Depends on the language. In C, they are the only way to pass objects by reference rather than value. In C++ there are normally ways to avoid using them (built-in references, smart pointers, std::vector to avoid manual dynamic arrays etc).I tend to use a pointer as a function argument in C++ if it can possibly be null, otherwise I'd use a reference. I find it quite rare to need this functionality and there are safer options that express this intent more clearly (boost::optional IIRC).   ;  Pointers are very useful - just a little hard to use sometimes.   Some languages use pointers behind the scenes.  When you create and use an object in Delphi or Object Pascal, you are actually get back a pointer to the object:obj := TMyObject.Create;obj.Name := 'Bob';In the example, "obj" is a pointer, but it just doesn't look like one because of compiler magic.   However it can still be used just like a pointer, so its the best of both worlds, imo.Anyway, on to an example:Say you're writing a dinosaur combat game and you want a herd of 100 Seismosaurs to charge across the screen.One way to make this happen would be to instance a single Seismosaur model in memory, create a pointer to that model, and share that pointer with the 100 game objects representing the charging herd.By using a pointer in this case, you save memory because you don't need 99 extra Seismosaur models cluttering up RAM when only one will do the trick.  =)The same technique can be applied to other types of game objects, such as textures, materials, sounds, etc.   ;  I repeat this over and over to anyone who asks about when to use pointers. Build a linked list.Do that. Once you have a working linked list, come back here.   ;  In C:-They're used to provide reference semantics.-Dynamic memory allocationIn C++:-When you need to perform pointer arithmetic on a parameter.-When you need "re-seatable" reference semantics.-When a parameter may be null (better options exist).-Compatability with legacy interfaces.-"Raw" dynamic memory allocation.   ;Quote:Original post by oler1sBuild a linked list.This.   ;  I'll just say the same thing last time I replied to this topic:First search the forums, this topic is like beating a dead horse, it has been covered numerous times. If you are still fuzzy on when to use them then you probably want to avoid them!Practice learning to write programs first and when you start to write games that use C++ and DirectX using pointers then ask this question again if you still having problems.Also, if you decide to do any MFC or Objective-C programming you won't be able to avoid them.On the other hand, remember millions of programmers, I'm thinking VB6, got by for many years without having to deal with pointers. Hence, one of the reasons VB6'ers they were probably looked down upon by other programmers. On a side note, you can write a linked list in Java/C# without messing with pointers at all too.In the new Stroustroup Swan book, he doesn't even cover pointers until PartIII and even then only because of the following reasons:#1 - you would be unable to implement a new container (should you need one, and that's not uncommon). i.e. custom linked list as suggest other things not in STL#2 - You would be unable to read huge amounts of C and C++ code that directly uses memory. i.e. DirectX, MFC, majority of freely available open-source code like Linux kernel#3 - More philosophically, I am among the large group of computer professionalswho are of the opinion that if you lack a basic and practical understanding ofhow a program maps onto a computer's memory and operations, you will haveproblems getting a solid grasp of higher-level topics, such as data structures , algorithms,and operating systemsI agree with #3.   ;  Thanks for the answers. I've written something similar to a linked list in a class where I learned C. I'm doing C++ now, and I'm pretty sure I know HOW to use pointers... I was just confused when to use them over say a reference. Thanks.   