Here goes a example program:
#include<stdio.h>
void text();/* we need to declare that we are using this function in program */
int main()
{
text()/* calling function text */
printf("The message peinted above is from function test.");
return 0;
}
void text
{
printf("How is your day\?\n");
}
Output:
How is your day? The message peinted above is from function test.
In this program above we define two functions main() and text()
we use the function test in three location. The first is to inform the program that we are using text function. Its like informing to friends before visiting them.
Second time inside the main function to call the function from main function. so now the programs go the the function text and perform the task and come back and continue.
At last we create a function. that's all.
A function can be called any numbers of time as needed. we can create any numbers of functions as needed. we can call any function(except main) from from any function. But another function cannot defined inside another function.
Basically there are two types of functions:
Library Functions: pritnf() scanf() etc and
User defined functions text() message()
A functions can be named any but should no be the keyword.
0 comments:
Post a Comment