322 Programming and Data Structures
fUE.'/
f
c -
printf ( mn In fun OlBยป%d Cm%d*,b,c);
}
OUTPUT;
In main () B= 10 C=5
In fun 0 B = ll C=4
Again In main 0 B= 12 C=3
Explanation In the above program variables V and 'c' are defined outside the main ( ) , hence
they are global. They can be called by any other function. The same variables V and 'c! are used
throughout the program. In main (), values of V and 'c' are printed.
The function fun () is called, V is incremented and 'c' is decremented. The values of V and 'c'
are printed. The control then returns to the function main ().
Again 'b' is incremented and 'c' is decremented. The values of V and 'c' are printed. Here, both
the functions use the same variables.
g) Return value: It is the outcome of the function.The result obtained by the function is sent back
to the calling function through the return statement.The return statement returns one value per
call. The value returned is collected by the variable of the calling function.
10.4 THE RETURN STATEMENT
The user-defined function uses a return statement to return the value to the calling function. Exit
from the called function to the calling function is done by the use of a return statement. When a
return statement is executed it always returns 1.
10.5 Write a program to use a return statement in different ways.
# in clu d e<stdio.h>
# include cconio. h>
main()
{
in t pass (in t );
in t x ,y;
c lr s c r ();
printf("Enter value of x:"fc
scanf("%d",&x*
if(x==l I I x<0)
return 0;
y=pass(xfc
switch(y)
{
case 1