Pascal - Return Pointer from Subprograms
- Details
- Category: Chapter 3
- Published: Sunday, 14 April 2013 18:02
- Written by Sternas Stefanos
- Hits: 15677
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