.: EMICROS :.  Embedded Micro Software
Home CAN232 CANUSB I2C232 I2CUSB CanWiser Learn C
Add your text here
Contact

Email : info@emicros.com

Ordering Information

.: Ordering using our PayPal powered shopping cart (PayPal account not required).

CAN232 : $79
CANUSB : $89
I2C232 : $79

I2CUSB : $89

Click here to View Cart and check out.

 

 

 

 

Functions

Functions are to C what subroutines are to Basic. A function is a collection of C statements that can be called from other functions and can be passed data and/or can return data.

The following table shows a few examples.

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 );
}

 

 
 
Copyright 2010 Embedded Micro Software. All rights reserved