C as a Procedure Oriented Programming Language

Another step into the wide world of C. In the first tutorial, Beginning with C Programming Language, you must’ve stumbled upon the fact that C is a procedural programming language. In this tutorial, we discover more about the procedural aspect of C. Before we talk about procedural programming it is important for us to learn about programming paradigms.

1. Programming Paradigms

Programming paradigms refer to the style of writing the program depending on the programmer’s choice on how he chooses to place the different elements of programming in a sensible code. Most programming languages fall under only one programming paradigm but there are a few languages that can have multiple paradigms like C which is both procedural and functional programming language.

Here are a few common programming paradigms:

  • Procedural Programming: It is based on procedures and allows stepwise sequential execution(explained in detail below). Eg: C, Go, Fortran, Pascal, Ada, and BASIC
  • Functional Programming: It is mostly used for mathematical functions where it takes an argument and returns a value. Eg: Common Lisp, Scheme, Clojure, Wolfram Language, F#, etc.
  • Object Oriented Programming: It is a programming language that makes use of objects which is a bundle of both data and methods. Eg: JAVA, C#, C++, VB.NET, etc.
  • Logical programming : As the name suggests logical programming is based on logic, problem domains, relations and facts. Eg: Prolog, Datalog, ASP.

2. Procedural Programming

Procedural programming stems from Structured programming and is based on the concept of the Procedure call. It is a programming paradigm that makes use of procedures(also called routines, subroutines, or functions). Most of the programming languages in the early days were Procedural. Procedural Programming is also known as Imperative Programming. It has well-structured computational steps which make use of features like modularity and scoping to enhance its readability and decrease its complexity.

Modularity refers to the systematic division of a complex code into small modules. It reduces the complexity of a program and makes it easier to find and edit any part of the code if required.

Scoping refers to enclosing the variables, constants, and other statements and functions in a module. Scoping and modularity are closely related as scoping are used to implement modularity.

A program gets divided into small modules for which the variables have a scope and cannot/can be accessed by other functions according to the programmer’s choice.

Let’s have a look at a simple procedure of finding the maximum number from two user input numbers (flow chart).

max number flowchart
Flow chart to find maximum of two numbers

Here we see a simple program in the form of a flow chart. Although this process can be done using other programming paradigms here we focus on the Procedural paradigm.

In the flow chart, we see sequential steps which show the actual flow of execution(based on decisions) that will be followed to execute the program. It goes sequentially by taking two numbers as input in the first step, comparing them in the second, and resulting in the output in the third step. Thus, we get a picture of how Procedural programming works.


Although most programming paradigms are similar in many aspects, it has certain differences which distinguishes one from the other. Let’s look at the comparison of Procedural Programming with  a couple of other Programming Paradigms:


3. Procedural vs Object-Oriented Programming

  • In procedural programming the data and function are treated as different elements of a program whereas, in OOP, both are wrapped into the same bundle known as an object.
  • In Procedural programming most of the data and variable have a global access because there are no access specifiers in Procedural Programming. On the other hand, OOP offers access specifiers which can restrict the usage of the data and variables to a particular method(Eg: public, private, protected,etc).
  • Procedural programming has a Top-down approach to programming whereas, OOP has the Bottom-up approach to programming.

These are basic differences between procedural programming and Object oriented programming.


4. Procedural vs Functional Programming

  • Procedural programming follows a series of steps for the execution of the code, whereas, functional programming can randomly go to a step depending on the function it needs to perform.
  • Functional programming makes use of sub-routine calls or tail calls and higher order functions instead of imperative loops used by procedural programming.
  • In Functional programming, programming is done by expressions and declarations rather than statements as used by procedural programming.

These are basic differences between procedural programming and Functional programming.


Helpful Links

Please follow C Programming tutorials or the menu in the sidebar for the complete tutorial series.

Also for the example C programs please refer to C Programming Examples.

All examples are hosted on Github.


Recommended Books


An investment in knowledge always pays the best interest. I hope you like the tutorial. Do come back for more because learning paves way for a better understanding

Do not forget to share and Subscribe.

Happy coding!! 😊

Recommended -

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x