//************************************** // Name: A Beginner's Guide to Pointers // Description:An Example on the Usage of Pointers // By: Ty (from psc cd) // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:Always be careful to know the exact location in memory pointers are aiming at before changing the values they point to. //************************************** //Free Source Code Tutorials Free for the taking //Blazon Resources //http://www.members.home.net/blazonres // //Email at blazonres@home.com #include <iostream.h> void main() { int MemoryAddress = 0; //Value in memory to point to int *Pointer; //Stores(Points to) value of memory location Pointer = &MemoryAddress; //Point to the address of 'MemoryAddress' //No '*' used here because it points to the location of 'MemoryAddress' //Pointer now knows where the value of 'MemoryAddress' is and //therefore can be used to change it (as used here from 0 to 1) cout << MemoryAddress << endl; //Show the value of 'MemoryAddress' *Pointer = 1; //Point to the location in memory and change the value to 1 cout << MemoryAddress << endl; //Show the new value of 'MemoryAddress' on the screen } /* NOTE: Changing the value of an unknown memory location may cause the computer to crash or lose vital information causing serious problems. Ommitting the line: "Pointer = &MemoryAddress;" will cause the program to change a nearly random location in memory which could cause serious damage to the computer. So be sure to define the location in memory that is intended to be changed */