Pointy Birds

Last week, and last night we covered C++ pointers, basically it seems to boil down to the following bits. A pointer to an integer object which contains the value 1, can be written as:

int* fred = new int( 1 );

which can be split into three parts:

a. int* fred which declares fred as a pointer to an integer.
b. fred = new int; which allocates enough memory to hold the integer to which fred points
c. *fred = 1; which puts the value of 1 into the object to which fred points ( or *fred )

Pointers can be passed to and returned from functions ( and also need to be deleted in certain circumstances which didn’t get explained), if a pointer is passed into a function then, the object to which it points can be altered, and the ampersand used when we pass by reference is also an address, thereby providing us with a pointer to something.