A function definition is a group of statements that
is executed when it is called from some point of the program. The general
syntax is
return_type function_name (parameter1, parameter2,
....., parametern)
{ - - - - -
statements ;
- - - - -
}
Where,
􀂃 return_type
is the data type specifier of data returned by the function.
􀂃 function_name
is the identifier by which it will be possible to call the function.
􀂃 Parameters
(as many as needed) : Each parameter consists of a data type specifier followed
by an identifier like any regular variable declaration. (for eg: int x) and which
acts within the function as a regular local variable. They allow to pass arguments
to the function when it is called. The different parameters are separated by
commas.
􀂃 Statements
is the function’s body. It is a block of statements surrounded by braces{}.
􀂃The
first line of the function definition is k/a function header.
#include<stdio.h>
int addition (int a, int b) /* function prototype */
main()
{ int 2 ;
2 = addition (5,3) ; /*function call */
printf (“The result is%d”z) ;
}
int addition(int a, int b) /* function header */
{ int r;
r = a+b
return r;
}
Output:
The result is 8
Comments
Post a Comment