Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Practice Problems
  • Python
  • C
  • C++
  • Java
  • Courses
  • Machine Learning
  • DevOps
  • Web Development
  • System Design
  • Aptitude
  • Projects
Open In App
Next Article:
What are Operators in Programming?
Next article icon

Modular Approach in Programming

Last Updated : 07 Sep, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report

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.

  • 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 concept of modular programming approached.
  • 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.

Points which should be taken care of prior to modular program development:

  1. Limitations of each and every module should be decided.
  2. In which way a program is to be partitioned into different modules.
  3. Communication among different modules of the code for proper execution of the entire program.

Advantages of Using Modular Programming Approach –

  1. 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.
  2. Reusability :It allows the user to reuse the functionality with a different interface without typing the whole program again.
  3. 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.

Example of Modular Programming in C

C is called a structured programming language because to solve a large problem, C programming language divides the problem into smaller modules called functions or procedures each of which handles a particular responsibility. The program which solves the entire problem is a collection of such functions.
Module is basically a set of interrelated files that share their implementation details but hide it from the outside world. How can we implement modular programming in c? Each function defined in C by default is globally accessible. This can be done by including the header file in which implementation of the function is defined.
Suppose, we want to declare a Stack data type and at the same time want to hide the implementation, including its data structure, from users. We can do this by first defining a public file called stack.h which contains generic data Stack data type and the functions which are supported by the stack data type.
In the header file we must include only the definitions of constants, structures, variables and functions with the name of the module, that makes easy to identify source of definition in a larger program with many modules.
Keywords extern and static help in the implementation of modularity in C.

stack.h:           extern stack_var1;           extern int stack_do_something(void);            

Now we can create a file named stack.c that contains implementation of stack data type:

stack.c  #include  int stack_var1;  static int stack_var2;    int stack_do_something(void)  {    stack_var1 = 2;    stack_var2 = 5;  }  

The main file which may includes module stack

  #include  int main(int argc, char*argv[]){  while(1){    stack_do_something();      }  }  


Next Article
What are Operators in Programming?
author
niharika123
Improve
Article Tags :
  • School Programming
  • CBSE - Class 11
  • Programming Basics
  • school-programming

Similar Reads

  • Modulus Operator in Programming
    The modulus operator, often represented by the symbol '%', is a fundamental arithmetic operator used in programming languages to find the remainder of a division operation between two numbers. It returns the remainder of dividing the first operand by the second operand. Table of Content What is the
    5 min read
  • What are Operators in Programming?
    Operators in programming are essential symbols that perform operations on variables and values, enabling tasks like arithmetic calculations, logical comparisons, and bitwise manipulations. In this article, we will learn about the basics of operators and their types. Table of Content What are Operato
    15+ min read
  • Modular Arithmetic for Competitive Programming
    In mathematics, modular arithmetic refers to the arithmetic of integers that wraps around when a certain value is reached, called the modulus. This becomes particularly crucial when handling large numbers in competitive programming. This article "Modular Arithmetic for Competitive Programming" will
    11 min read
  • Loops in Programming
    Loops or Iteration Statements in Programming are helpful when we need a specific task in repetition. They're essential as they reduce hours of work to seconds. In this article, we will explore the basics of loops, with the different types and best practices. Table of Content What are Loops in Progra
    12 min read
  • Introduction of Programming Paradigms
    A paradigm can also be termed as a method to solve a problem or accomplish a task. A programming paradigm is an approach to solving a problem using a specific programming language. In other words, it is a methodology for problem-solving using the tools and techniques available to us, following a par
    11 min read
  • What is a Block in Programming?
    In programming, a block is a set of statements that are grouped and treated as a single unit. Blocks are used to define the scope of variables, control the flow of execution in conditional statements and loops, and encapsulate code in functions, methods, or classes. Table of Content What is a Block
    6 min read
  • What is a Code in Programming?
    In programming, "code" refers to a set of instructions or commands written in a programming language that a computer can understand and execute. In this article, we will learn about the basics of Code, types of Codes and difference between Code, Program, Script, etc. Table of Content What is Code?Co
    10 min read
  • R - Object Oriented Programming
    In this article, we will discuss Object-Oriented Programming (OOPs) in R Programming Language. We will discuss the S3 and S4 classes, the inheritance in these classes, and the methods provided by these classes. OOPs in R Programming Language:In R programming, OOPs in R  provide classes and objects a
    8 min read
  • Introduction to Programming Languages
    Introduction: A programming language is a set of instructions and syntax used to create software programs. Some of the key features of programming languages include: Syntax: The specific rules and structure used to write code in a programming language.Data Types: The type of values that can be store
    13 min read
  • Blog | Programming Guidelines
    Computer programming is a process of writing an executable computer program for accomplishing a specific computer task. Although writing the programs is an art, however, there should be some minimum guidelines that should be followed while writing programs. Name: Define the variable names as per pro
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences