Computer Languages

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484

Modular Programming and Functions

What does Modular Programming mean?

·       Some programs might have thousands or millions of lines and to manage such programs it becomes quite difficult as there might be too many of syntax errors or logical errors present in the program, so to manage such type of programs, there is a concept of modular programming.

·       Modular programming is the process of subdividing a computer program into separate sub-programs.

·       A module is a separate software component. It can often be used in a variety of applications and functions with other components of the system.

·       Each sub-module contains something necessary to execute only one aspect of the desired functionality.

·       Modular programming emphasis on breaking of large programs into small problems to increase the maintainability, readability of the code and to make the program handy to make any changes in future or to correct the errors.

Why do we use Functions in C language?

What are advantages of using Modular Programming Approach?

·       Ease of Use: This approach allows simplicity, as rather than focusing on the entire thousands and millions of lines code in one go we can access it in the form of modules. This allows ease in debugging the code and prone to less error.

·       Reusability: It allows the user to reuse the functionality with a different interface without typing the whole program again.

·       Ease of Maintenance: It helps in less collision at the time of working on modules, helping a team to work with proper collaboration while working on a large application.

Functions

·       In c Function, a large program is divided into the basic building blocks known as function.

·       The function contains the set of programming statements enclosed by {}.

·       A function can be called multiple times to provide reusability and modularity to the C program.

·       In other words, the collection of functions creates a program. The function is also known as procedure or subroutine in other programming languages.

Function Aspects

There are three aspects of a C function.

·       Function declaration A function must be declared globally in a c program to tell the compiler about the function name, function parameters, and return type.

·       Function call Function can be called from anywhere in the program. The parameter list must not differ in function calling and function declaration. We must pass the same number of functions as it is declared in the function declaration.

·       Function definition It contains the actual statements which are to be executed. It is the most important aspect to which the control comes when the function is called. Here, we must notice that only one value can be returned from the function.

The syntax of creating function in c language is given below:

return_type function_name (data_type parameter...)

{  

//code to be executed  

}  

Types of Functions

There are two types of functions in C programming:

·        Library Functions: are the functions which are declared in the C header files such as scanf(), printf(), gets(), puts(), ceil(), floor() etc.

·        User-defined functions: are the functions which are created by the C programmer, so that he/she can use it many times. It reduces the complexity of a big program and optimizes the code.

 

 

Return Value

A C function may or may not return a value from the function. If you don't have to return any value from the function, use void for the return type.

Example

Let's see a simple example of C function that doesn't return any value from the function.

void Display()

{

       printf(“Welcome”);

}

 

C Language Video

Computer Languages

Back - C Language Notes By Vivek Sir email: vivekdubey22@gmail.com (w) 9826424484