Archived

This topic is now archived and is closed to further replies.

Andrew Nguyen

Pointers

Recommended Posts

I know what pointers do, how to use them, and when their used in strings. But when using numbers, and non-array data, what is their use? After that, I got a pretty good grasp on C++

Share this post


Link to post
Share on other sites
other than what you mentioned, pointers can be used if you want to directly change the value being passed to a function.
for example...

void foo(int *num)
{
*num = 10;
}

int main()
{
int ass = 4;

foo(ass);
}

after the call to foo(), ass will lose its value of 4 and become 10. get it?



...go on and live with no regrets, you only have one life...

Share this post


Link to post
Share on other sites
If calling a function that takes a parameter larger than the size of the pointer itself, its faster to pass a pointer to it instead. Same with returning values, faster to return a pointer than a block of data larger than the pointer.

Storing global variables as pointers to them is better than having the globals as normal variables (again in the case that their size is larger than the pointer... no use having a pointer to a boolean)

-----------------------
0wn 0wn 0wn your goat
gently down the pw33n

Share this post


Link to post
Share on other sites