Functions: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
This example is on functions. With Functions you need to state the return type of the function. Either int or void. Int is value used for returning something to a call, mainly used for returning integers such as the add function in the following program. Void is used for functions that dont return a value or you dont want to return a value. You must use int or void in every function you make. Take a look at the following program: | |||
<pre> | <pre> | ||
#include <stdio.h> | #include <stdio.h> | ||
Revision as of 03:34, 9 April 2007
This example is on functions. With Functions you need to state the return type of the function. Either int or void. Int is value used for returning something to a call, mainly used for returning integers such as the add function in the following program. Void is used for functions that dont return a value or you dont want to return a value. You must use int or void in every function you make. Take a look at the following program:
#include <stdio.h>
void cfile(char *file)
{
FILE *fp = fopen(file, "w");
fprintf(fp, "example");
fclose(fp);
}
int add(int x, int y)
{
int r;
r = x + y;
return(r);
}
int main()
{
cfile("example.txt");
add(1,1);
return 0;
}