1.

Explain About Pass By Ref And Pass By Value?

Answer»

Pass by value is the default method through which arguments are passed into FUNCTIONS and tasks. Each SUBROUTINE retains a local copy of the argument. If the arguments are changed within the subroutine declaration, the changes do not AFFECT the caller.

In pass by reference functions and tasks directly access the specified variables passed as arguments.Its like passing pointer of the variable.

EXAMPLE:

task pass(int i) // task pass(var int i) pass by reference 
{
delay(10);
i = 1;
printf(" i is changed to %d at %dn",i,get_time(LO) );
delay(10);
i = 2;
printf(" i is changed to %d at %dn",i,get_time(LO) );
}

Pass by value is the default method through which arguments are passed into functions and tasks. Each subroutine retains a local copy of the argument. If the arguments are changed within the subroutine declaration, the changes do not affect the caller.

In pass by reference functions and tasks directly access the specified variables passed as arguments.Its like passing pointer of the variable.

example:

task pass(int i) // task pass(var int i) pass by reference 
{
delay(10);
i = 1;
printf(" i is changed to %d at %dn",i,get_time(LO) );
delay(10);
i = 2;
printf(" i is changed to %d at %dn",i,get_time(LO) );
}



Discussion

No Comment Found