recall the function f(x)=x^2 and the function we built. The lecture is linked here.
#include <stdio.h>
#include "function.h"
/*
The function.h header file's contents is the
function prototype.So you can use the function
*/
main()
{
// declare variables
int a, y, z;
a = f(2); // the first function call
y = 5;
z = f(y); // the second function call
/* Printing the Results To the Screen */
printf("a = %d \n", a);
printf("z = %d \n", z);
}
function.h
int f(int x);
function.c
f(int x) // This part is the function definition
{
int result;
result = x*x;
return result
// Alternatively, you could just use the code below
// return x*x;
}
Now we can use separate compilation by executing the compile command below.
cc driver.c function.c -o app