
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses


In this task, the goal is to demonstrate common operations on pointers and references. These examples show pointer operations on the stack, which can be dangerous and is rarely done. Pointers and references are commonly used along with Memory allocation on the heap.

program pointerDemo;
 
type
	{
		A new pointer data type is declared by `↑` followed by a data type name,
		the domain.
 
		The domain data type may not have been declared yet, but must be
		declared within the current `type` section.
 
		Most compilers do not support the reference token `↑` as specified in
		the ISO standards 7185 and 10206, but use the alternative `^` (caret).
	}
	integerReference = ^integer;
 
var
	integerLocation: integerReference;
 
begin
	{
		The procedure `new` taken one pointer variable and allocates memory for
		one new instance of the pointer domain’s data type (here an `integer`).
		The pointer variable will hold the address of the allocated instance.
	}
	new(integerLocation);
 
	{
		Dereferencing a pointer is done via appending `↑` to the variable’s
		name. All operations on the domain type are now possible.
	}
	integerLocation^ := 42;
 
	{
		The procedure `dispose` takes one pointer variable and releases the
		underlying memory. The supplied variable is otherwise not modified.
	}
	dispose(integerLocation);
	{
		In Pascal, `dispose` is not necessary. Any excess memory is automatically
		released after `program` termination.
	}
end.