/* * function.c * basic concepts of functions */ #include int a; // global variable, visible from anywhere. void function1(); // function declaration or prototype, function without return value int function2(int); // function with int return value, has int parameter, need to pass int argument in function call int main() { int x = 2; a = 1; // assign value 1 to global variable a function1(); // call function1 int y = function2(x); // call function2, pass value of x, i.e. 2 to function2, and assign returned value to variable y printf("a=%d, y=%d", a, y); return 0; } // function definition/implementation, no return value void function1() { int y = 2; // y is local variable a += y; } // function definition/implementation, with return value int function2(int x) { // parameter x is int type int z = x + 2; function1(); // call another function return z; // return value } /* a=5, y=4 */