Project Goals

Our goal is to provide first and second year University students with a simple game that allows them to build the intuition and understanding of pointers as used in high level languages like C/C++. An educational game online could help motivate and engage these students to participate in a meaningful and educational activity and to explore key concepts outside of the classroom. Putting their theory into practice reinforces the theoretical elements and aids in their retention.

Friday, May 16, 2008

Pointer Syntax

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:
  • int *pointer;

Initialization -- At this point, "pointer" could easily be invalid, so it needs to be initialized.

  • int *pointer = NULL;
"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"
  • *pointer = 3;

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: