Pascal - Return Pointer from Subprograms
A function can return a pointer as its result. The following program illustrates returning pointer from a function:
program exPointersFromFunctions; type ptr =^integer; var i: integer; iptr: ptr; function getValue(var num: integer): ptr; begin getValue:=@num; end; begin i :=100; iptr := getValue(i); writeln('Value deferenced: ', iptr^); end.
When the above code is compiled and executed, it produces following result:
Value dereferenced: 100