Function in C programming

-- Leave a Comment
A function in C is a block of statements that perform task of some kind. Every c program have collections of functions. You can use a function to perform certain task that are usually need to be done so that for every time you need to preform that task you don't need to rewrite the code insist call the function to do that task. Its something like hiring  some person to do some special task for you.
Here goes a example program:

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");

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.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University, NCIT. Open Source Enthusiastic.


Post a Comment