2. THERE ARE TWO WAYS IN WHICH WE CAN
PASS ARGUMENTS TO THE FUNCTION
3. CALL BY VALUE
Value of actual arguments passed to the
formal arguments.
Any change made in the formal arguments
does not effect the actual arguments.
When function is called it does not affect the
actual contents of the actual arguments.
4. #include <stdio.h>
void call_by_value(int x)
{
printf("Inside call_by_value x = %d before adding 10.n", x);
x += 10;
printf("Inside call_by_value x = %d after adding 10.n", x);
}
int main() {
int a=10;
printf("a = %d before function call_by_value.n", a);
call_by_value(a);
printf("a = %d after function call_by_value.n", a);
return 0;
}
EXAMPLE PROGRAM
5. OUTPUT OF THE PROGRAM
a = 10 before function call_by_value.
Inside call_by_value x = 10 before
adding 10.
Inside call_by_value x = 20 after
adding 10.
a = 10 after function call_by_value.
6. Actual and Formal arguments
Arguments passed to the function during function call
are known as actual arguments
The arguments we use during a function definition are
known as formal arguments.
7. For a function call to be valid the type, order and number of
actual and formal arguments must always be same.
Value of each of the actual arguments in the calling function
is copied into the formal arguments of the called function.
Changes made have no effect on the values of actual
arguments in the calling function.
Concept of Actual and Formal
arguments
8. CALL BY VALUE CALL BY REFERENCE
CALLING FUNCTION SENDS COPIES TO
DATA.
THE FORMAL PARAMETERS ARE
ORDINARY VARIABLES.
ATMOST ONLY ONE VALUES CAN BE SENT
BACK TO THE CALLING FUNCTION.
ACTUAL PARAMETERS ARE AFFECTED BY
CHANGES MADE WITHIN THE FUNCTION.
CALLING FUNCTION SENDS ADDRESS OF
DATA.
THE FORMAL PARAMETERS ARE POINTER
VARIABLE.
SEVERAL RESULTS CAN BE SENT BACK
TO THE CALLING FUNCTION.
DIRECT CHANGES ARE MADE TO THE
ACTUAL PARAMETERS.