-->

Working of a function in C language

Working of a function in C language

Working of a function

main ()
{
int s;
..............
..............
..............
s = abc(x,y,x);

.....
...
}
abc(l,k,j);
{
int q;
......
.......
return (q);
}

Actual arguments:
Variables passed as parameters to the function are called arguments
The arguments in the call statement in the calling function are called actual arguments. In the above program, variables ‘x’, ‘y’ and ‘z’ are actual arguments.

Formal arguments:
The arguments in the declaration and definition of the function are formal arguments. Here, variables ‘l’, ‘k’, and ‘j’ are formal arguments.
These arguments are enclosed within the parenthesis. They must be separated by a comma (,). These formal arguments receive values from the actual arguments.
In the program ‘s’ receives the returned value from the function.
Function name:
A function name must follow the same rules as we use for identifier naming. In fact, a function name is an identifier
Example: sum(int a, int b);
Where, sum() is a user-defined function and ‘a’ and ‘b’ are integer variable arguments.
The function call must end with a semi-colon (;).
Function call:
A function can be called simply using its name like other C statement, terminated by a semi colon (;)
A compiler executes the function, when a semi-colon (;) is en-counted after the function name.
Return Value:
Return value 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 a calling function.

There are three ways to return a control from a called function to the point, at which the function was invoked(called)
1. If the function does not return a result, control is simply returned when the function-ending right brace is reached, or by executing the statement;
return;
2. If the function does return a result, the statement;
return expression;
3. returns the value of expression to the caller
Syntax of return statement
return(expression); /*returns the value of expression to the caller */
or
return; /*if the function does return a result the statement*/

Actual arguments in functions,Formal arguments in functions,difference between actual arguments and formal arguments

Actual arguments in functions,Formal arguments in functions,difference between actual arguments and formal arguments



Related Posts

Subscribe Our Newsletter