Procedural Programming Tutorial

Procedural Programming

Introduction To Procedural Paradigm

The procedural programming aims at dividing the large program into smaller programs called procedures. The procedures are also alternately referred to as subprograms , subroutines, methods or functions.

In procedural programming , the program code is organized as set of procedures called functions. These functions operate on the program data called the variables.

In procedural programming , the program data is in the form of variables. The functions  operate on the program data. Each function consist of computational statements and solves a part of the problem.

Procedural Programming

The procedural programming continues to be the preferred choice for the beginners as a first programming language. The C procedural language is extensively used in the industry for the system programming.

Despite the advent of other paradigms ,the procedural programming paradigm is still very popular and a part of the syllabus in most of the educational institutes and universities.

The procedural programming is a programming paradigm that is derived from structured programming. And the structured programming is derived from imperative paradigm.

Procedural Programming Paradigm

This tutorial will help you learn the procedural programming paradigm in the most simplified language. In this tutorial, you will also learn important features of the procedural programming , its advantages and disadvantages, and other important related topics .

Let us start with a simple introduction to the procedural programming.

Procedural Programming

Table Of Contents

What Is Procedural Programming ?

The procedural programming paradigm is also alternately referred to as procedure oriented programming . The procedure is a key element of this paradigm.

In procedural programming , the program code is divided into group of smaller programs called functions. Each function performs a specific task depending upon the program logic.

As the name suggest,  the procedural programming the program code is organized in the form of procedures. These procedures are also called as subroutines or functions.

Procedural Program Organization

The function can access and operate upon its own local data as well as global data shared by all the functions.

In procedural programming , the function becomes the most important component of the program and the functions have unrestricted access to the global data.

Each procedure or subroutine consist of set of program statements to complete a specific task . The program can have may procedures and the procedure can be called many times in the program code.

Definition Of Procedural Programming

The procedural programming paradigm is defined as a programming paradigm ( program organization style ) that allows the program to be organized as a set of functions.

Any  function can be called many times in the program code as and when required to perform the same task.

In this paradigm , the program statements are grouped together based on the functionality. These group of statements can be named suitably as function as per the language syntax.

For example , we can group program statements that accepts two number as user input , then add these numbers and return the result value.

Function Declaration

Function Declaration

Procedural Program Organization

The procedural program code is written as sequence of subroutines ( functions or procedures ).

The procedures can either be defined into the main program code or outside the main program code into a separate header file.

In order to improve the readability of the code, the subroutines can also be defined in a separate file that can be included in the main program as a header file.

In procedural programming , when the program size is becomes large then the program code is split into group of smaller programs called procedures or subroutines.

Program Organization

Procedural Program Organization Example

Each subroutine performs a specific task. For example , the programmer can write a subroutine to add two or more numbers or subtract numbers .

The subroutine or procedure can be written to perform repetitive task in the program code as per the program logic. This helps to eliminate the repetition of code.

The well organized procedural program code is relatively much easier to read and debug . Such code is also easier to maintain.

The program code in the procedural programming is exacted sequentially using a top-down approach.

Features Of Procedural Programming

The procedural programming paradigm has some important features . These features define the program organization , program execution sequence and the scope of the variables.

Top Down Approach

The top down approach defines the execution sequence of the program . In this approach the program execution starts at the top and the program statements are executed one after another.

However , the programmer has many options to change the program execution sequence by using program flow control statements.

Header Files Declaration

The header files offers a convenient way to organize the program code in procedural programming. The header file inclusion statements are declared at the top section of the program.

The header files can contain predefined library functions . For example , in C language programming, the Stdio.h ( Header File ) files contains the standard function declarations for commonly used input and output functions.

The header file can also contain library of used defined functions for common functionality that can be used in many software projects.

Predefined Library Functions

Most procedural programming language offer extensive library of predefined functions. These library functions are available and can be readily used in the program code.

It is simply now possible for the programmer to write all the functions required for the desired functionality. And therefore , the predefined library functions are used to reduce the overall development time.

User Defined Library Functions

All procedural programming language offer programmer option to write the user defined functions. The user can define these functions to handle the specific functionality into the program code.

The programmer can create the library of functions that can be commonly used in many software development projects.

Function Parameters

In simple words , the parameters are the place holders that holds the values passed on to the function in the function call statement in the program code.

The function declaration defines the list of the parameters that must be sent to the function . The number of parameters and its data type depends upon the functionality performed by the function.

The function prototype statement and the function declaration defines the number of parameters , its order and the data type of the arguments ( passed values ).

Passing Values To The Function

The function declaration contains the details of the parameters that are required to be sent to the function during the function call.

The parameters are variables that works like a placeholder for the values sent to the function. The values can be passed to the function either by value or by reference.

The parameters declared in the function prototype declaration is referred as parameter. Whereas  the actual values that are passed during the function call are referred as arguments.

Variable Scope

The scope of the identifier decides the accessibility of that identifier within the program code. The variable scope defines the accessibility and the visibility of the variable.

For example , a variable declared inside the function block is treated as a local variable . The local variable can be accessed anywhere inside the function body.

Whereas, the variable declared outside the function block is treated as a global variable . The global variable can be accessed anywhere in the program code.

Since the global variable can be access and operated by any function makes it vulnerable inadvertent change and this might affect the functionality of the other functions that also share the same data.

Advantages And Disadvantages of Procedural Programming

The procedural programming has its own advantages and disadvantages.

Advantages Of Procedural Programming

  1. The procedural programming languages are relatively much easier to learn as first programming language for the beginners.
  2. The straight forward program organization makes it ideal choice as a general purpose language.
  3. The procedural programming language such as C Language is still being used for many application.
  4. The C language has extensive library of functions suitable for various applications. This prewritten code already used and tested is readily available to the programmer.
  5. The use of standard library functions bring down significant reduction in the overall development cost and time.
  6. The concept of pointers in the procedural programming C language allows low level memory operations.

Disadvantages Of Procedural Programming

  1. The procedural programming is not suitable for large and complex software project.
  2. It is difficult to represent the real world objects realistically in the procedural programming. Whereas , in object oriented programming , it is much easier to represent the real world objects.
  3. It is difficult to protect the data from inadvertent changes since most data is generally global leading to the problem of spaghetti code.
  4. The software maintenance is relatively difficult for a procedural programming software.
  5. For procedural programming paradigm , the function is the most important component of the program and the data does not get the due attention.

Difference Between Procedural Programming And Object Oriented Programming

Let us now understand the difference between the  procedural paradigm approach and the Object Oriented Programming ( OOP ) approach.

Procedural Paradigm

  1. The procedural paradigm decomposes the program into set of functions.
  2. The procedural paradigm is based on top down approach for program execution.
  3. The procedural paradigm gives unrestricted access to the global data and data access cannot be controlled using access specifier .
  4. The function is the most important component of the procedural paradigm.
  5. The procedural paradigm cannot bind the data and function together.
  6. It is difficult to represent the real world objects.
  7. The procedural paradigm is not suitable for large and complex software.
  8. In procedural paradigm, it is difficult to add new functionality.
  9. In procedural paradigm, the software maintenance is difficult.
  10. In procedural paradigm, It is difficult to protect the data from inadvertent changes .

OOP Paradigm

  1. The OOP paradigm decomposes the program into set of objects.
  2. The OOP paradigm is based on bottom up approach for program execution.
  3. The OOP paradigm does not give unrestricted access to the data. The data access can be tightly controlled using the access specifier .
  4. The data is the most important component of the OOP paradigm.
  5. The OOP paradigm can bind the data and function together as a class.
  6. It is much easier to represent the real world objects in OOP paradigm.
  7. The OOP paradigm is suitable for a large and complex software.
  8. In OOP paradigm, it is much easier to add new functionality.
  9. In OOP paradigm, the software maintenance is relatively much easier.
  10. In OOP paradigm, It is possible to protect the data from inadvertent changes .

Example Of Procedural Programming.

Procedural Programming Example

Join The Best Seller

Computer Science Online Course

This is the most comprehensive  and unique  Computer Science  And Programming Fundamentals course Online which will give you in depth understanding of most important fundamental concepts in computer science And Programming .

Don`t copy text!