We will probably want to reference pointer syntax (in C?) in our game -- wikipedia does a really good job of explaining it, but I'd like to keep a copy in here for us (because some of it is so basic to what a pointer is, we could easily forget to add it to the game).
Definition -- "pointer" is a pointer to an integer:
Initialization -- At this point, "pointer" could easily be invalid, so it needs to be initialized.
"If a NULL pointer is deferenced, then a runtime error will occur and execution will stop likely with a segmentation fault."
Assignment -- Using the pointer:
- int variable = 7;
- int *pointer = NULL;
- pointer = &variable;
Note where the * and & are located. We've just assigned "the value of [pointer] to the address of [variable]. For example, if [variable] is stored at memory location of 0x8130 then the value of [pointer] will be at 0x8130 after the assignment"
Here we are changing the contents of "pointer" (at the memory address 0x8130 -- which is also still referenced by "variable") from 7 to 3. Printing the value of variable at this point would now output "3".
No comments:
Post a Comment