Escolar Documentos
Profissional Documentos
Cultura Documentos
CONTENTS:
Parameters can be classified into three groups or modes. They can be
used to:
1. Pass information to a sub-program.
2. Return information from a sub-program.
3. Pass information to a sub-program where it is updated and then returned.
CALL BY VALUE
Call by value is the most common and is used by languages such as
C,Pascal, Modula-2 and Algol-60. Here the formal parameter acts as a
local variable which is initialised with the value of the actual parameter
(which may be a variable, a constant or an expression) and may then
be changed. However, any changes made to the formal parameter will
not effect the value of the actual parameter.
C Example:
#include <stdio.h>
void main(void)
{
int value1, value2, value3;
scanf("%d %d %d",&value1,&value1,&value3);
doit(value1,value2,value3);
CALL BY REFERENCE
The disadvantage of call by value is that a copy is always made of the
actual parameter to obtain the formal parameter. The need to make a
copy can be avoided using the call by reference mechanism. In call by
reference the address of the actual parameter is passed, thus
everything that happens to the formal parameter actually happens to
the actual parameters.
CALL BY REFERENCE
In the C programming language the effect of call by reference can be
achieved by passing a reference as a value. Knowledge of this
reference can then be used to alter the value held in it. This
mechanism thus only simulates call by reference and should (more
accurately) be referred to as call by reference value.
C Example:
#include <stdio.h>
void meanValue(float *, float);
void main(void)
{
float value_1, value_2;
scanf("%d %s\n",&value_1,&value_2):
meanValue(&value_1, value_2);
#include <stdio.h>
void main(void) {
char myString[32];
toUpper(myString);
/* Output result */