home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
modula2
/
mod2src.arc
/
POINTERS.MOD
< prev
next >
Wrap
Text File
|
1987-03-08
|
772b
|
32 lines
(* Chapter 12 - Program 1 *)
MODULE Pointers;
FROM InOut IMPORT WriteString, WriteInt, WriteLn;
FROM Storage IMPORT ALLOCATE, DEALLOCATE;
FROM SYSTEM IMPORT TSIZE;
TYPE Name = ARRAY[0..20] OF CHAR;
VAR MyName : POINTER TO Name; (* MyName points to a string *)
MyAge : POINTER TO INTEGER; (* MyAge points to an INTEGER *)
BEGIN
ALLOCATE(MyAge,TSIZE(INTEGER));
ALLOCATE(MyName,TSIZE(Name));
MyAge^ := 27;
MyName^ := "John Q. Doe";
WriteString("My name is ");
WriteString(MyName^);
WriteString(" and I am ");
WriteInt(MyAge^,2);
WriteString(" years old.");
WriteLn;
DEALLOCATE(MyAge,TSIZE(INTEGER));
DEALLOCATE(MyName,TSIZE(Name));
END Pointers.