Skip to main content
gamedev.net
🔒 Locked

Pointers

Started by PHPCoder 2 replies 800+ views
Original Post
PHPCoder
PHPCoder
What are pointers used for in C++?
Hot Dog
Hot Dog
Sorry... don't quite understand your question.

Pointers in C++ are alot like pointers in other languages. Pointers *point* (no pun intended) to a location in memory. It is like a handle (my own term, not the C++/CLI handle) that allows you to manipulate that piece of memory.

Some common uses of pointers:

1) manipulating values/objects
Instead of passing around by value that can get pretty inefficient in terms of the value/object copying, you pass around the pointer to that value/object. You can then manipulate that value/object via its pointer using "->" operator.

2) manipulating functions
Using function pointers (i.e.: pointers that point to functions of specific prototype), you can actually get your program to call functions during runtime, whose specific names are not known at compile time. A related use is also to implement function callbacks (i.e.: basically a mechanism by which a function can "callback" the function that called it in the 1st place).

3) manipulating arrays
This is actually similiar to point (1) above. Instead of passing around and manipulating the actual array elements, you pass around and manipulate them via the array pointer.

There are other great uses for pointers.

Hope that was useful to you.

Have fun! :)

Joshua

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.