Function call in User-Defined Function

Started by thiruvasagamani, Sep 22, 2008, 11:15 AM

Previous topic - Next topic

thiruvasagamani

Function call:

A function is called by its name,function call is branching,control branches to called function and executes it.Statement following the function call is executed only after called function terminates.

main()
{
----
----
f1();
----
----
}
f1()
{
-----
-----
}

From the above sequential execution is suspend due to function call.

Syntax:

variable = function name(parameters);
function name(parameters);
parameter in function call are sent to function

eg:
1. x = pow(2 , 3);
8 is return to variable x
2. sqrt(25);
5 is return to function call and is ignored since there is no variable on left hand side
3. x = clrscr(); // error
Left hand side variable is not allowed for void function
4. x = max(a, max(b , c));
Function call in function call is nested call , inner call is made before outer call, 1st call is max(b , c), 2nd call is max(a , result).X contains largest of a ,b ,c
5. x = max(max( a ,b), max(c , d));
Parameters evaluation is from right to left , first call is max(c , d), second call is max(a , b), third call is max( result, result) contains largest of a, b , c , d

Invalid:
void f1()
{
-----
----
void f2()
{
-----
-----
}
-----
-----
}

We cannot define a function within another function , nested calls are ok but not nested defintions
Thiruvasakamani Karnan