Pointer: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (cleanup)
Line 1: Line 1:
[[Category:Variables]][[Category:Glossary]]
[[Category:Variables]][[Category:Glossary]]
{{stub}}
{{stub}}
'''Pointers''' are special in C++. '''Pointers''' can be used to point to a [[variable]] instead of becoming a variable.  Here is an example: There are 5 [[integer]] [[variable]]s. Each one is named accordingly (anInteger1, anInteger2, ect).  However we have a [[function]] that uses whatever [[integer]] the user chooses.
 
'''Pointers''' are special in C++. '''Pointers''' can be used to point to a [[variable]] instead of becoming a variable.  Here is an example: There are 5 [[integer]] [[variable]]s. Each one is named accordingly (anInteger1, anInteger2, etc.).  However we have a [[function]] that uses whatever [[integer]] the user chooses.


Enter '''pointer'''s.
Enter '''pointer'''s.
Line 11: Line 12:
The main advantage to pointer is that they do not waste memory.  in the function, we are working with the actual integer variable, rather than a copy of it.  This has its disadvantages however.  If we will be editing the entered integer value, but do not wish to edit the original variable, pointers will not suffice.
The main advantage to pointer is that they do not waste memory.  in the function, we are working with the actual integer variable, rather than a copy of it.  This has its disadvantages however.  If we will be editing the entered integer value, but do not wish to edit the original variable, pointers will not suffice.


== Pointers in Scripting ==
== Pointers in scripting ==
There are also pointers used in scripting (i.e. !activator). See [[targetname]] for a list of them.
There are also pointers used in scripting (i.e. !activator). See [[targetname]] for a list of them.


== External Links ==
== External links ==
[[Wikipedia:Pointer|Wikipedia information on pointers]]
[[Wikipedia:Pointer|Wikipedia information on pointers]]

Revision as of 02:02, 1 October 2007

Stub

This article or section is a stub. You can help by expanding it.

Pointers are special in C++. Pointers can be used to point to a variable instead of becoming a variable. Here is an example: There are 5 integer variables. Each one is named accordingly (anInteger1, anInteger2, etc.). However we have a function that uses whatever integer the user chooses.

Enter pointers.

When running the program, the user makes his choice to pick whatever integer he wants. When that happens, the pointer is pointed toward that integer. Finally, whenever the user is ready, he will continue to the next stage, where a function is run to return the value of the integer he has chosen.

The function will automatically pick whatever integer we have the pointer aimed at.

The main advantage to pointer is that they do not waste memory. in the function, we are working with the actual integer variable, rather than a copy of it. This has its disadvantages however. If we will be editing the entered integer value, but do not wish to edit the original variable, pointers will not suffice.

Pointers in scripting

There are also pointers used in scripting (i.e. !activator). See targetname for a list of them.

External links

Wikipedia information on pointers