return_type function_name( parameter list )
{
body of the function
}
/ * Function returns the larger of the two numbers number * / int max ( int num1, int num2) { / * local variable declarations * / int Result; IF (num1> num2) Result = num1; the else Result = num2; return Result; }
#include <stdio.h> / * function declarations * / int max ( int num1, int num2); int main () { / * local variables defined * / int A = 100 ; int B = 200 is ; int RET; / * call the function to get the maximum value * / RET = max (a, B); the printf ( " max value iS:% D \ n- " , RET); return 0 ; } / * function returns the larger of the two numbers in the number of * / int max ( int num1, int num2) { / * local variable declarations * / int Result; IF (num1> num2) Result = num1; the else Result = num2; return Result; }
/ * Function definition * / void the swap ( int x, int y) { int TEMP; TEMP = x; / * save the value of x * / x = y; / * the y assigned to x * / y = TEMP; / * temp assigned to the Y * / return ; }
#include <stdio.h> / * function declarations * / void the swap ( int X, int Y); int main () { / * local variables defined * / int A = 100 ; int B = 200 is ; the printf ( " exchange before , the value of a:% D \ n- " , a); the printf ( " before the exchange, b value:% D \ n- " , b); / * invoke the function to exchange value * / the swap (a, b); the printf ( " after the exchange, the value of a:% d \ n " , a); the printf ( " after the exchange, b value:% d \ n ", b ); return 0; }
/ * Function definition * / void the swap ( int * x, int * y) { int TEMP; TEMP = * x; / * save the value of the address of x * / * x = * y; / * the y assigned to x * / Y = temp *; / * the temp assigned to Y * / return ; }
#include <stdio.h> / * function declarations * / void the swap ( int * X, int * Y); int main () { / * local variables defined * / int A = 100 ; int B = 200 is ; the printf ( " before the exchange, the value of a:% D \ n- " , a); the printf ( " before the exchange, b value:% D \ n- " , b); / * invoke the function to exchange value * & a represents pointing a pointer, i.e., the address of a variable * & b to point b represents a pointer, i.e. the address of the variable b * / the swap ( & a, & b); the printf ( " After the exchange, the value of a:% D \ n- ' , a); the printf ( " After the exchange, b value:% D \ n- ' , b); return 0 ; }