Advertisement

Pointers

Started by December 31, 2001 02:16 PM
1 comment, last by Andrew Nguyen 22 years, 11 months ago
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++
---START GEEK CODE BLOCK---GCS/M/S dpu s:+ a---- C++ UL(+) P(++) L+(+) E--- W++ N+ o K w(--) !O !M !V PS- PE+Y+ PGP+ t 5 X-- R tv+ b+ DI+ D G e* h! r-- !x ---END GEEK CODE BLOCK---
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...
...go on and live with no regrets, you only have one life...
Advertisement
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
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack

This topic is closed to new replies.

Advertisement