Unit1 - Procedural Theory
Unit1 - Procedural Theory
Unit 1
Overview of the Unit
TextBook: Shalom, Elad. A Review of Programming Paradigms Throughout the History: With a
Suggestion Toward a Future Approach, Kindle Edition
Procedural Programming
History and Languages
Overview
Concepts and their representation in C
Modularity
Variables
Special variables - pointers
Variable scope
Functions
Recursion
Static functions
Example with different procedural approaches
Review of concepts in other languages
History and Languages
The high-level form rather than time-consuming lower level
languages - assembly and machine language.
Machine-independent form - portable, lifetime andusefulness
Procedural programming was born around 1958,
before structured programming and other paradigms.
Procedural programming was necessary to enable
breaking complex programs into smaller units –
procedures
Compiler Vs Interpreter
Procedural – either compiled or interpreted
FORTRAN – implemented with compiler
BASIC – implemented with interpreter
Programming language : ALGOL , COBOL , Pascal, Modula, C
Compiler Vs Interpreter
COMPILER INTERPRETER
Advantages of Modularity
int main()
{
// function call
int i = func();
}
// function definition
int func()
{
return 0;
}
Special variables - pointers
type *var-name;
int *ip; /* pointer to an
integer */
double *dp; /* pointer to a double */
float *fp; /* pointer to a
float */
char *ch /* pointer to a
character */
int *ptr = NULL;
Variable scope
A scopein programming is a region of
the program where a defined variable existsbut
cannot be accessed beyond it.
Inside a function or a block where they are
called local variables;
Outside of all functions where they are called
global variables.
In the definition of function parameters where they
are called formal parameters.
Local Vs Global Variable
#include <stdio.h>
int main ()
{
/* local variable declaration */
int g = 10;
return 0;
}
Local Vs Global Variable
#include <stdio.h>
int main ()
{
Output
value of g
/* local variable declaration */ = 10
int g = 10;
return 0;
}
Functions
A special function with the name main() is
the first one to run when the program starts.
Examples on function return type
int rename();
extern int rename();
void sayHello(int number_of_times)
Functions using Arrays
Call by Value
Call by Reference
Recursion
Static functions
Example with differentprocedural approaches
Using Recursion
Review of concepts in other
languages
ALGOL
Functional procedures
Functional procedures are the procedures that have
resulting value
Proper procedures
proper procedure do not return a value.
While both types are just called functions in C, ALGOL
and some other languages distinguish these types.
In case of a proper procedure, there is no
need to write void to signalize that there is no
returning type. Instead, simply procedure is written
without any type coming before it.
In FORTRAN and BASIC, user-defined functions
Characteristics of Procedure-Oriented Programming