Pointers
See https://www.freepascal.org/docs-html/ref/refse15.html
null
pointers in pascal is nil
.
See also https://en.wikibooks.org/wiki/Pascal_Programming/Pointers
var
p: ^integer;
i: integer;
begin
i := 3;
p := @i; // get the address of i
p^ += 2; // equivalent to *p += 2 in c/c++
Writeln('i is ', i); // is is 5
end.
The
new
function from https://www.freepascal.org/docs-html/3.2.0/rtl/system/new.htmlIt is declared as:
procedure New( var P: Pointer );
Note that the argument type is
Pointer
, which is an untyped pointer. Also note the argument isvar
, meaning it is an input/output argumentExample:
var p: ^integer; begin New(p); // allocate space and save the address to p p^ := 10; writeln ('p^ is ', p^); // p^ is 10 Dispose(p); // free p end.
GetMem()
andFreeMem()
See https://www.freepascal.org/docs-html/3.2.0/rtl/system/freemem.html
FillByte()
,FillChar()
,FillWord()
,FillDWord()
, are similar tomemset
in C/C++.https://www.freepascal.org/docs-html/3.2.0/rtl/system/fillchar.html