menu prev next

Value Parameters
In the previous programs, when variables are passed to procedures, the procedures work with a copy of the original variable. The value of the original variables which are passed to the procedure are not changed.

The copy that the procedure makes can be altered by the procedure, but this does not alter the value of the original. When procedures work with copies of variables, they are known as value parameters.

Consider the following code example,


	program  Value_Parameters (output);

	procedure  Nochange ( letter : char; number : integer );
	begin
	     writeln( letter );
	     writeln( number );
	     letter := 'A';        {this does not alter mainletter}
	     number := 32;         {this does not alter mainnumber}
	     writeln( letter );
	     writeln( number )
	end;

	var  mainletter : char;    {these variables known only from here on}
	     mainnumber : integer;
	begin
	     mainletter := 'B';
	     mainnumber := 12;
	     writeln( mainletter );
	     writeln( mainnumber );
	     Nochange( mainletter, mainnumber );
	     writeln( mainletter );
	     writeln( mainnumber )
	end.


PROGRAM SIXTEEN
Write a program, using procedures which accept value parameters, to implement the calculator program as derived in program fifteen. Each procedure will print out its own result. No global variables must be used.

Click here for answer


Copyright B Brown/P Henry/CIT, 1988-1997. All rights reserved.
menu prev next

1