|
The main() function is the first C function executed
after a reset. |
main()
{
}
|
|
This example shows the recommended way to declare a
function that requires no parameters and returns
nothing. |
void main( void )
{
}
|
|
This example shows a function f1 called with 2
parameters that returns the sum of the parameters. This
example actually lacks a function prototype of the f1
function so that the compiler can figure out how to
handle the data going to and coming from f1. |
void main( void )
{
x = f1( 10,20 );
}
int f1( int a, int b )
{
return( a + b );
} |
|
Corrected showing the f1 function prototype. |
int f1( int, int );
void main( void )
{
x = f1( 10,20 );
}
int f1( int a, int b )
{
return( a + b );
} |
|
Functions that appear before being used do not need a
function prototype. |
int f1( int a, int b )
{
return( a + b );
}
void main( void )
{
x = f1( 10,20 );
} |
|
The f1 and f2 functions in this example are contained
on 1 line. This is not recommended normally because it
can be confusing. |
int f1( int a, int b ){ return( a + b ); }
int f2( int a, int b ){ return( a - b ); }
void main( void )
{
x = f1( 10,20 );
y = f2( 10,20 );
} |