Game Development Reference
The following code can now be used to set the value of myNumber to 13 through the
pointer myNumberPtr .
*myNumberPtr = 13;
*myNumberPtr can be read as “the integer located at the memory value address held by
Finally, pointers can also be declared for structs.
Consider the following struct definition and code:
public int x;
public int y;
public int z;
CartesianCoord coord = new CartesianCoord();
CartesianCoord* coordPtr = &coord;
You can now use the pointer coordPtr to access public fields of coord .
This can be done with the following code:
Or the following equivalent code, which uses the indirection operator:
C++ developers are used to declaring statements like the following to save typing:
int* int1, int2;
Those developers would assume that int1 is a pointer to an integer, and int2 is just an integer.
C# handles this statement differently, as the pointer declaration is on the type, not the variable. In
this example, both int1 and int2 are pointers to integers.