Tuesday 6 June 2023

Function in C

What is function in C language?

A function is independent subprogram that is denoting to do some specific, described task. A C program be made up of one or more functions. If a program has only one purpose then it must be the main() function.

Function in C language, function returning value
Function in C language image-1

1.1   Advantages of using functions:

1.       Normally a inconvenient problem is separated into sub problems and then solved. This divided and beat skill is implemented in C through functions. A program can be separated into functions, each of which executes some particular task. So the use of C functions designed or produced in separate piece or parts and divides the work of a program.

2.       When some particular code is to be used more than once and at dissimilar places int eh program, the use of functions keep away from retelling of that code.

3.       The program suit simply comprehensible, modifiable and easy to detect and test. It becomes easy to write the program and interpret what work is done by each part of the program.

4.       Functions can be retaining in a library and the state or quality of  being reusable can be achieved.

C programs have two types of functions:

1.       Library functions

2.       User-defined functions

 

1.2   Library functions

C has the space to prepare library functions for carry out some working. These functions are present in the C library and they are limited. The functions scanf() and printf() are input output library task. Similarly we have functions like strlen(), strcmp() for string unscrupulous.

To use a library function we have to embrace function header file using the hardware or software that processes information before it heads to another program directive #include. For example to use input output task like printf(), scanf() we have to embrace stdio.h, for string library string.h should be included.

 

1.3   User-Defined Functions

Users can produce their own function for execute any particular task of the program. These types o functions are called varied by the user functions. To create and use these functions, we should know about these three things they are:

1.       Function definition

2.       Function call

3.       Function declaration

 

1.4   Function definition

The function definition is made up of the whole illustration and code of a function. It tells what the task is doing and what are its inputs and outputs. A function definition contain of two parts – a function header and a function body.

 

1.5   Function call

The function definition report what a function can do, but to literally use it in the program the function should be called to some place. A function is called by simply writing its name come after by the disagreement list inside the parentheses.

 

1.6   Function Declaration

The calling function needs data about the called function. If explanation of the called function is placed before the calling function, then statement is not needed.


Computer stuff kit tricks of Topics 50.