09.10.2014 Views

download pascal tutorial (pdf - Tutorials Point

download pascal tutorial (pdf - Tutorials Point

download pascal tutorial (pdf - Tutorials Point

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Value of num = 3000<br />

Value available at ptr^ = 3000<br />

Value available at pptr^^ = 3000<br />

Address at ptr = 36864<br />

Address at pptr = 36880<br />

Passing <strong>Point</strong>ers to Subprograms<br />

<strong>Point</strong>er variables may be passed as parameters in function and procedure arguments.<br />

<strong>Point</strong>er variables can be passed on both as value and variable parameters; however, when<br />

passed as variable parameters, the subprogram might inadvertently alter the value of the<br />

pointer which will lead to strange results.<br />

The following program illustrates passing pointer to a function:<br />

program ex<strong>Point</strong>ertoFunctions;<br />

type<br />

iptr = ^integer;<br />

var<br />

i: integer;<br />

ptr: iptr;<br />

function getNumber(p: iptr): integer;<br />

var<br />

num: integer;<br />

begin<br />

num:=100;<br />

p:= @num;<br />

getNumber:=p^;<br />

end;<br />

begin<br />

i := getNumber(ptr);<br />

writeln(' Here the pointer brings the value ', i);<br />

end.<br />

When the above code is compiled and executed, it produces the following result:<br />

Here the pointer brings the value: 100<br />

TUTORIALS POINT<br />

Simply Easy Learning Page 99

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!