^
In ASCII the character code decimal 94 (or hexadecimal 5E) is defined to be ^ (circumflex accent).
For any data type, a pointer type for that data can be declared using the operator ^ in front of the data type.
program pointerDemo(input, output, stderr);
type
listItem = record
payload: integer;
// next _points_ _to_ a list item
next: ^listItem;
end;
var
start: ^listItem;
begin
new(start);
if not assigned(start) then
begin
writeLn(stderr, 'obtaining memory for start failed');
halt(1);
end;
A pointer can be followed, dereferenced by appending a ^ to the identifier.
Instead of having the memory address in your hands, you will look at the memory content at that address.
If it is a typed pointer, operations and syntax for that type are valid, e.g. assignment in the following example.
// _de-reference_ the pointer, i.e. follow it
start^.payload := 7;
dispose(start);
end.
However, attempting to follow a nil pointer will cause a runtime error (RTE 216 “general protection fault”).
That is the situation the condition not assigned(start) in line 15 is supposed to catch.
see also
edit{$pointerMath off}disallows usage of pointers in arithmetic expressions{$typedAddress on}in conjunction with the@-address-operator{$modeSwitch autoDeref-}
| single characters | + (plus)
•
- (minus)
•
* (asterisk)
•
/ (slash)
= (equal)
•
> (greater than)
•
< (less than)
. (period)
•
: (colon)
•
; (semi colon)
^ (hat)
•
@ (at)
$ (dollar sign)
•
& (ampersand)
•
# (hash)
' (single quote) |
| character pairs |
|