Advertisement
2002VB Coding Standards #25119

A Beginner's Guide to Pointers

An Example on the Usage of Pointers

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
//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
*/
Original Comments (3)
Recovered from Wayback Machine