En Cours Functions
En Cours Functions
Dr Dalila bouras
Blida1 university
Why Functions?
• So far, we have stayed inside the main function. We have never exited
it.
• Almost no program is written solely within the curly braces of the main
function.
Syntax:
Example
// is e q u i v a l e n t to
Example:
Example:
# include
<stdio .h> #
include <stdlib .h>
Example:
The main function calls the printf function, which in turn calls the
triple function. It’s a nesting of functions.
Formal Parameters Vs. Actual Parameters
int main ()
{
...
printf (" The triple is % d\ n", triple ( input
Number ));
...
}
1. The names of the arguments in the function header are called "formal
parameters." Their role is to describe what the function should do
within its body.
2. The arguments provided during the use (the call) of the function are called
"actual parameters." Any expression can be used as an actual parameter.
Passing Parameters by Value
Example:
• In principle, the order of definitions in the program text does not play
a role, but each function must be declared (prototyped) or defined
before being called.
• The default type is int; in other words, if the type of a function is not
explicitly declared, it is automatically int.
• The order of definitions in the program text does not play a role, but each
function must be declared (prototyped) or defined before being called.