Topic 1: Introduction to Structured Programming
This topic focuses on the foundational concepts of structured programming, its principles,
history, and role in programming languages. Below is a detailed analysis of the subtopics:
1. Definition
✓Structured programming is a programming paradigm that emphasizes breaking down a
program into smaller, manageable, and logical blocks or modules.
A paradigm is a model, framework, or pattern used as a basis for understanding or
organizing concepts in a particular field. In the context of programming, a paradigm refers to a
style or approach to writing and organizing code that guides how problems are solved and how
solutions are structured.
Programming Paradigms
Programming paradigms define how programming tasks are conceptualized and executed. Key
paradigms include:
1. Procedural Programming Paradigm
Focuses on step-by-step instructions and functions.
Example: C, Pascal.
2. Object-Oriented Programming (OOP) Paradigm
Organizes code into objects that contain data (attributes) and methods (functions).
Example: Java, Python, C++.
3. Functional Programming Paradigm
Treats computation as the evaluation of mathematical functions.
Avoids changing states or mutable data.
Example: Haskell, Lisp.
4. Logic Programming Paradigm
Solves problems using facts, rules, and queries based on formal logic.
Example: Prolog.
5. Event-Driven Programming Paradigm
Focuses on responding to events such as user actions or messages from other programs.
Example: JavaScript.
6. Declarative Programming Paradigm
Focuses on what the program should accomplish rather than how to accomplish it.
Example: SQL, HTML.
General Definition
In summary, a paradigm serves as a guiding principle or methodology, whether in programming,
science, or other disciplines, to solve problems systematically and efficiently.
✓Interpreter is a tool in the code blocks that translates and execute c program line by line at
run time.
✓Assembler is a program or a tool in the code blocks that converts, assemble language into
machine language. ( It is often used in the compilation process after the compiler generates
secular code before creating machine codes).
✓Compiler is a program that translates the entre c source code into a machine code allowing
the program to be executed by the computer. (It change the syntax and sematic in the program).
Key features include:
✓Use of control structures like sequences, selection, and iteration.
✓Avoidance of unstructured jumps (e.g., goto statements).
✓Emphasis on modular design.
✓ Simplicity
✓ Efficiency
✓ Modularity
✓ Compatible
✓ Rich in libraries
2. Principles of Structured Programming
The core principles include:
1. Top-down Design
Breaking a program into smaller sub-programs or modules.
Each module is independent and focuses on a specific task.
2. Control Structures
Using three main constructs:
Sequence (step-by-step execution).
Selection (decision-making using if, switch).
Iteration (loops like for, while).
3. Modularity
Programs are divided into reusable and maintainable functions or procedures.
4. Clarity and Readability
Writing clean, logical, and well-documented code for better understanding.
5. Avoidance of Redundancy
Using functions to eliminate repetitive code.
3. Advantages of Structured Programming
Readability: Clear and well-organized code that is easy to understand and debug.
Reusability: Modules and functions can be reused in different parts of the program.
Maintainability: Easier to update or modify specific sections of the program.
Reduced Complexity: Dividing programs into smaller modules simplifies problem-solving.
Error Reduction: Improved organization reduces logical errors and bugs.
4. Disadvantages of Structured Programming
✓Time-Consuming: Designing a structured program requires more time compared to
unstructured programming.
✓Not Suitable for All Problems: Some complex problems may require unstructured approaches
or object-oriented programming.
✓Limited Flexibility: Strict adherence to principles may limit creativity in problem-solving.
✓No memory management
✓Not object oriented program
✓Low level language
5. Types of Structured Programming
Structured programming languages are those that support the principles of structured
programming, emphasizing clarity, modularity, and the use of control structures like sequence,
selection, and iteration. Below are the types of structured programming languages based on
their paradigms:
1. Procedural Programming Languages
These languages follow a procedure-driven approach, where the program is divided into smaller
functions or procedures.
Characteristics:
Focuses on step-by-step instructions.
Uses control structures like if, for, and while.
Supports modularity through functions or procedures.
Examples:
C: A general-purpose language often used for system-level programming.
Pascal: Designed for teaching structured programming.
FORTRAN: Used for numerical and scientific computing.
2. Object-Oriented Programming Languages
Though primarily object-focused, these languages support structured programming principles.
Characteristics:
Combines structured programming with object-oriented concepts like encapsulation,
inheritance, and polymorphism.
Breaks the program into objects that model real-world entities.
Examples:
C++: Combines C's procedural nature with object-oriented features.
Java: Fully object-oriented, but adheres to structured programming principles for control flow.
Python: Supports structured and object-oriented programming.
3. Functional Programming Languages
These languages treat computation as the evaluation of mathematical functions and avoid
changing state or mutable data.
Characteristics:
Focus on modular, reusable functions.
Limited or no side effects in functions.
Examples:
Lisp: Early functional language that supports structured concepts.
Haskell: Focuses on pure functional programming with structured constructs.
4. Scripting Languages
Scripting languages also support structured programming for specific tasks or automation.
Characteristics:
Often interpreted rather than compiled.
Used for web development, automation, or lightweight programming tasks.
Examples:
JavaScript: Widely used for web development with structured control flow.
PHP: Designed for dynamic web content and supports structured programming.
5. Modular Programming Languages
These languages emphasize dividing the program into independent, reusable modules.
Characteristics:
Each module performs a specific function.
Encourages code reusability and organization.
Examples:
Modula-2: Specifically designed for modular programming.
Ada: Focuses on modular and structured approaches.
Summary
Types of Structured Programming Languages include:
1. C language - programming language that is commonly used for its efficient and control of
systematic problems
2. Pascal - A programming language designed for teaching concepts in control and algorithms.
3. Python - A programming language for data analysis.
4. Java - A programming language for app development
All these languages incorporate the principles of structured programming, enabling developers
to create clear, maintainable, and modular code.
6. History of Programming Languages
Early Programming Languages
Low-level assembly languages used in the 1940s and 1950s.
First Generation (1950s)
Machine language (binary codes).
Second Generation (1950s-1960s)
Assembly language introduced.
Third Generation (1960s-1980s)
High-level languages like C, COBOL, and Fortran emerged.
Fourth Generation (1980s-1990s)
NoFocused on database query languages (e.g., SQL).
Fifth Generation (1990s - Present)
Involves AI-based languages like Python and Prolog.
7. High-Level and Low-Level Programming
>Low-Level Programming
Close to hardware, e.g., assembly language.
Faster execution but harder to write and debug.
>High-Level Programming
Closer to human language, e.g., C, Python.
Easier to write, read, and debug but requires compilation to machine code.
Summary
This provides the theoretical foundation for structured programming, its historical development,
and its advantages. It also introduces the classification of programming languages into low-level
and high-level, setting the stage for practical programming concepts in subsequent topics.
TOPIC 2: VARIABLES
This topic introduces the concept of variables in C programming, their types, and how to use
them effectively.
1. Definition
A variable is a named storage location in memory used to hold data. Its value can change
during the program's execution.
2. Types of Variables
1. Local Variables
Declared inside a function or block.
Accessible only within that function or block.
Automatically deallocated after function execution.
2. Global Variables
Declared outside all functions.
Accessible throughout the program.
3. Static Variables
Retain their value even after the function exits.
Declared using the static keyword.
4. External Variables
Declared in another file or scope.
Use the extern keyword to access them.
3. Naming of Variables
>Rules for naming variables:
-Must begin with a letter or an underscore (_).
-Can include letters, numbers, and underscores.
-Cannot use keywords (e.g., int, return).
-Must be unique within the same scope.
Examples:
int score;
float _price;
char firstName[20];
-Avoid using spaces or void when combining 2 or 3 names to form one variable name but you
can combine using underscore. Eg: NET_SALARY
-Variables in c programming are case sensitive(in caps and lower case)
4. Using Variables in C Programming
Declare variables with a data type and optionally initialize them.
int age = 20;
float height;
height = 5.9;
5. Importance of Variables
Enable dynamic data storage and manipulation.
Improve code readability and maintainability.
Allow for efficient memory management.
Summary
Data Types define the kind of data that can be stored and manipulated, ensuring proper
memory allocation and preventing type errors.
Variables act as containers for data and are essential for storing, modifying, and retrieving
values during program execution. Together, they form the backbone of any C program.
TOPIC 3: DATA TYPES
This topic focuses on the classification of data used in C programming and how they are
implemented.
1. Definition
✓A data type specifies the type of data a variable can hold. It determines:
~The size of memory allocated for the data.
~The range of values that can be stored.
~The operations that can be performed on the data.
2. Types of Data Types
C programming supports several data types categorized as follows:
1. Primary (Basic) Data Types {Primitive data types}
-Used for storing simple values. Examples:
int (integers): Whole numbers.
int a = 7
float (floating-point): Decimal numbers.
float games = 7.125
double (double precision floating-point): Higher precision decimal numbers.
double length = 7.24
char (character): Single characters (e.g., 'A').
char grade = “D”
strings: combination of 2 or more characters
string name = “ Grace”
2. Derived Data Types
Created from basic types. Examples:
Arrays.
Pointers.
Functions.
3. User-Defined Data Types
Custom types defined by the programmer. Examples:
struct (structures).
enum (enumerations).
typedef.
4. Void Data Type
Represents no value. Typically used for:
Functions that do not return a value.
3. Using Data Types in C Programming
Declare variables with appropriate data types to optimize memory usage.
Syntax:
int age = 25;
float temperature = 36.5;
char grade = 'A';
4. Importance of Data Types
Memory Efficiency: Ensures appropriate memory allocation.
Data Validation: Restricts variables to specific types of values.
Program Accuracy: Prevents type-related errors.