Friday, 10 August 2018

Functions in C Program | Types and Use

A function is a self contained block or sub program of one or more statements that performs a specific task when called. C functions can be classified into two categories: Library functions and user defined functions.

1. Library functions are those functions which are already defined in " C Library". 

Ex: printf(); 

you just need to include appropriate header files to use these functions. These functions are already declared and defined in " C libraries" .

2. User defined functions are those functions which are defined by the user at the time of writing program to made for code reusability and for saving time and space.



Benefits of Using Functions

  1. It provides modularity to your program's structure.
  2. It makes your code reusable. You just have to call the function by its name to use it, wherever required.
  3. In case of large programs with thousands of code lines, debugging and editing becomes easier if you use functions.
  4. It makes the program more readable and easy to understand.
In a C program we use both user defined and predefined functions. But, in order to use user defined functions you need to tell what is it ( function declaration), when to use it (function call), how to use it (function definition).

Here is simple example program using functions which prints a simple greeting message.



void display(); // function decleration

 void main()
{

     display();  /* function call */
}

void display()     / * function definition */
{

  printf(" welcome to programming using functions");
}

0 comments:

Post a Comment

Scribe to Youtube Channel

Advertisement

Find Us On Facebook

C Programming

More

C++ Tutorial

More

Java Tutorial

More

software engineering

More

MS Office

More

Database Management

More
Top