- Pascal Tutorial
- Pascal - Home
- Pascal - Overview
- Pascal - Environment Setup
- Pascal - Program Structure
- Pascal - Basic Syntax
- Pascal - Data Types
- Pascal - Variable Types
- Pascal - Constants
- Pascal - Operators
- Pascal - Decision Making
- Pascal - Loops
- Pascal - Functions
- Pascal - Procedures
- Pascal - Variable Scope
- Pascal - Strings
- Pascal - Booleans
- Pascal - Arrays
- Pascal - Pointers
- Pascal - Records
- Pascal - Variants
- Pascal - Sets
- Pascal - File Handling
- Pascal - Memory
- Pascal - Units
- Pascal - Date & Time
- Pascal - Objects
- Pascal - Classes
- Pascal Useful Resources
- Pascal - Quick Guide
- Pascal - Useful Resources
- Pascal - Discussion
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 the following result −
Value dereferenced: 100
pascal_pointers.htm
Advertisements