Beruflich Dokumente
Kultur Dokumente
|
|
!
|
|
_ f any module has sub modules that is called as calling module and
sub modules are called called modules.
_ one module is communicate with other module through calling
module.
_ A c program consists of one or more functions, one and only one of
which must be named main.
_ the function which is calling other function is called calling function.
_ A function whom it called is called called function
_ A called function receives control from the a calling function, when
it completes its task, it returns control to the calling function.
_ the main function called by the operating system, in turn main
function calls the other function to do some task.
|
|
A large program divided into series of
individual related programs called
modules. These modules are called
functions.
Functions are classified into two categories
1. Library functions ( built_in functions).
2. User_defined functions
|
|
Library (built in) functions
C is a library it is a collection of various types of functions
which perform some standard and predefined tasks.
ƥ This are part of the c compiler that have been written for
general purpose are called library functions.
example
printf()
scanf()
sqrt()
Advantage
1.No need to write the code because the functions are
already available so it makes the programmers job much
easier.
2. these functions are used anywhere in the program.
|
|
User defined functions
|
|
Advantages of function
|
|
ð
¢
!
"
!
"
!
|
|
Definition
|
|
Ú
u
#
|
|
Function declaration
syntax
Return_type function_name (argument list);
|
|
Definition
Syntax for the function definition
Returntype function_name(argument list/parameters list)
argument list declaration
{
local variable declarations:
Statements;
return(expression);
}//function.
All the parts are not essential.
|
|
main()
{
___________
__________
func1();
_________
________
funct2();
________
_________
funct3();
_________
_______
}//main
func1()
{
__________
___________
}func1
func2()
{
________
________
}//func2
fucn3()
{
__________
_________
}//func3
|
|
Return type_ the type of value return by the
called function after its task finished off
|
|
main()\\calling function
{
func1();
printf(Ơwe are in main\nơ);
}//main
func1()\\ called funciton
{
printf(Ơwe are in func1\nơ);
}//func1
|
|
Points to remember
1. C program must have at least one fucntion
2. f program have one function it must be main
3. f program have more than function, in which one must
be main because program execution starts from that
only.
4. We can use unlimited no of functions in one program.
5. Each function is called in the sequence we have
specified in the main function.
6. After each function task is over the control passed to the
calling function(main()).
7
|
|
main()
{
printf(Ơ\n am calling other functionsơ);
func1();
func2();
func3();
Printf(Ơall functions are called\nơ);
}//main
func1()
{
printf(Ơin func1\nơ);
}//func1
func2()
{
printf(Ơin func2\nơ);
}//func2
func3()
{
printf(Ơin func1\nơ);
}//func3
Output:
|
|
!u$ % !
|
|
!u$ % !
|
|
!u$ % !
|
|
! & " " !
|
|
! ' !
!
|
|
!u$ !
!
|
|
!u$ !
!
|
|
!u$ !
!
|
|
! ( )
!
!
|
|
! * !
+
|
|
!u$ ) ,
|
|
!u$ ) ,
|
|
!u$ ) ,
|
|
!u$ ) ,
|
|
! - !
"
|
|