The data-type which preceeds the name of a function is simple the value which the function can return. The object of a function is to split a program into smaller more manageable parts. By only declaring variables within functions they cannot be used anywhere else in the program and this also reduces the space for error.
If you are just starting out you should consider using global variables. These are variables which are declared outside all functions including main(). (these are only really suitable for smaller programs eg. under 150 lines of code).
eg.
/* a simple function */
#include <stdio.h>
int a, b, c; /* declaring a, b, c as integer globals */
void simple_function ()
{
a = b + c;
}
main ()
{
b = 5;
c = 6;
simple_function (); /* executes the function simple_function */
printf ("the value of a is %d\n", a);
}
The other way to use functions is to pass data by value to the functions. This can be done also easily but maybe is a difficult concept for beginners to understand.
eg.
/* a simple program passing data to functions */
#include <stdio.h>
int simple_function (int a, int b)
{
int c;
c = a + b;
return (c); /* returns the value of c to main*/
}
main ()
{
int calculation;
/* perform calculation 5 + 6 */
calculation = simple_function (5, 6);
printf("the calculated value is %d\n", calculation);
}
I hope this helps in someway. C really is a great language though, stick at it!
B. Kernighan