Sign in Join
Wiki copytemporary

^

English · Suomi · Русский

^

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.

pascal
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.

pascal
    // _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


From the Free Pascal wiki, page "^", as it stood on 2023-02-18 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.