Showing posts with label user defined function in c programming language. Show all posts
Showing posts with label user defined function in c programming language. Show all posts

Thursday 8 March 2018

function or method in c programming

Functions:-

A function is a set of statements that together perform some specific task. Every C program has at least one function, which is main(),
A function can also be known as a method
There are some built in function available in c programming such as printf() is a standard library function to display output to the screen . This function is defined in "stdio.h" header file.
There are other  library functions defined under "stdio.h", such as scanf(), fprintf(), getchar() etc. Once you include "stdio.h" in your program, all these functions are available for use.

User-defined functions

C allow programmers to define functions. Such functions created by the user are called user-defined functions.

eg:-

 #include <stdio.h>
void functionName()
{
    ... .. ...
    ... .. ...
}

int main()
{
    ... .. ...
    ... .. ...

    functionName();
 
    ... .. ...
    ... .. ...
}

The execution of a C program begins from the main() function.
When the compiler encounters functionName(); inside the main function, control of the program jumps to

 void functionName()
And, the compiler starts executing the codes inside the user-defined function.

Advantages of user-defined function
It is easy to understand ,debug and maintain.
Reusable codes that can be used in other programs
A large program can be divided into smaller modules.Hence it is easy to understand

For more info click here