Write an Pascal Program For Dynamic Array By Incrementing a Pointer - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Saturday, September 23, 2017

Write an Pascal Program For Dynamic Array By Incrementing a Pointer

Dynamic Array Initialization By  Incrementing a Pointer

Program:

program exPointers;
const MAX = 3;
var
arr: array [1..MAX] of integer = (10, 100, 200);
i: integer;
iptr: ^integer;
y: ^word;

begin
(* let us have array address in pointer *)
iptr := @arr[1];

for  i := 1 to MAX do
begin
y:= addr(iptr);
writeln('Address of arr[', i, '] = ' , y^ );
writeln(' Value of arr[', i, '] = ' , iptr^ );

(* move to the next location *)
inc(iptr);
end;
end.

Output:
Address of arr[1] = 4248
Value of arr[1] = 10
Address of arr[2] = 4250
Value of arr[2] = 100
Address of arr[3] = 4252

Value of arr[3] = 200

No comments:

Post a Comment