Jun 22, 2020

Function's in C with there syntax, advantages & types

Definition: Function is a self-contained block of statement that perform a coherent tasks. using function  we can divide a large program into the basic building blocks.

There are many functions we are used already such as- printf()scanf()pow()sqrt() and most important function is main().

  Types of function's:

There are two types of function's.

  1. Standard library functions.
  2. User-defined functions.

1. Standard library functions:  Functions which already have a definition in header files(like stdio.h) this type of functions are called standard library functions. Which are printf()scanf()puts()gets() etc. 

2. User defined functions: The functions that we create in a program this type of functions are called as user defined functions.

In this tutorial we will learn how works user defined functions.


 return_type function_name (argument list)
 // block of statements

  • How It works?:
1.Return type: means  datatype such as int, double, char, float, void, short etc.

2.Function name: you can give any name to function. But to understand easily we will give meaningful name to functions.

3.Argument list: It contains variable names with there data types.

4.Block of statement/code: It will be executed whenever a call will be made to the function.

   Advantages of user defined functions:

1. The program will easier to understand by using functions.

2. It makes possible top down modular programming.

3. The length of the program can be reduced by using functions.

4. Large programs we can divide into  smaller modules using functions.

  Example program of user defined function:

Below program shows the working of the user defined functions.

void function();//function prototype declaration

void main()
 printf("Hii from main()\n");
 function();//function calling
void function()//function definition
 printf("Hii from user defined function");

Above program shows the following output:

Function's in C with there syntax, advantages & types

No comments:

Post a Comment

If you have any doubts, please discuss here...👇