CSE 1101
Structured Programming
Md Tajmilur Rahman
Lecturer
Dept. Of CSE, KUET
Lecture Topics
Lecture Topics No. of Lecture Topics No. of
classes classes
1. Introduction 1 7. Control statements (Loops) 2
2. Tokens, Data types and overflow 2 8. Functions 4
3. Variable and Constants 1 9. Variable length arguments 1
4. Operators 1 10. File handling 2
5. Type Conversions 1 11. Header files 1
6. Control statements (Branching) 2 12. Command line parameters 1
August 18, 2025 2
What is programming?
Instruction: A single command that tells the computer what to do.
Program: A collection of instructions arranged to perform a specific
task or to solve a problem.
Programming Language: A formal language used to write
programs (set of instructions) that a computer can understand and
execute.
Examples: C, Python, Java, C++.
August 18, 2025 3
Computer Languages
Human languages are known as natural languages.
Unfortunately, computers can not understand natural languages, as a
result we must communicate with computers using computer
languages. These languages are;
1. High Level Languages
2. Low Level Languages (Assembly Languages)
3. Machine Language
August 18, 2025 4
Machine language
Machine Language: The lowest-level programming language
consisting only of binary codes (0s and 1s) that the computer’s
CPU can directly understand and execute.
Machine Language: “01101011 00101000”
Machine language is a collection of binary digits or bits that the
computer reads and interprets.
August 18, 2025 5
Low Level Language(Assembly Language)
It uses mnemonic codes (short forms) for instructions and allows the
programmer to introduce names for blocks of memory that hold data.
Assembly language is designed to be easily translated into machine
language.
August 18, 2025 6
High Level Language
A programming language that is close to human language and
easy to understand, write, and debug. It uses words, symbols, and
syntax instead of binary or assembly.
Examples: C, Python, Java, C++, JavaScript.
High-level languages are translated into machine language using a
compiler or interpreter so the computer can execute them.
August 18, 2025 7
Program code converters
INTERPRETER:
Interpreter converts a source code , usually on a step-by-step, line-by
line and unit-by-unit basis into machine code.
COMPILER:
Compiler is a program that compile source code into executable
instructions that a computer can understand. Example: C compiler
ASSEMBLER: Assembler normally converts assembly language’s
source code into machine language. Example: GNU assembler
August 18, 2025 8
Types of programming
Structured Programming (C)
Object-Oriented Programming (C++)
Logic/Declarative Programming (Prolog)
Functional/Applicative Programming (Lisp)
August 18, 2025 9
Structured Programming
A programming style where a program is written by dividing it into small,
logical modules (functions/procedures) and using only control structures.
Each module is in turn divided into sub-modules until the resulting modules are
understood without further division. (Top down design)
August 18, 2025 10
Control Structures
1. Sequence: Step by step execution
2. Selection: if, else if, else, switch-case
3. Iteration: loops
4. Module: Functions
August 18, 2025 11
SEQUENCE
Statement 1 Statement 2 Statement 3 ...
sum = a + b; // Statement 1
printf("Sum = %d\n", sum); // Statement 2
printf("Program finished.\n"); // Statement 3
August 18, 2025 12
SELECTION (Branch)
IF Condition THEN Statement1 ELSE Statement2
Statements1
Statement
Condition ...
Statements2
August 18, 2025 13
LOOP(repetition)
WHILE ( Condition ) DO { Statement1 }
False
...
Condition
Body
August 18, 2025 14
SUBPROGRAM(function)
SUBPROGRAM1 ...
SUBPROGRAM1
a meaningful collection
of SEQUENCES,
SELECTIONS, LOOPS
August 18, 2025 15
The Four Stages of Compiling a C Program
1. Preprocessing
2. Compilation
3. Assembly
4. Linking
August 18, 2025 16
Preprocessing
This is the first phase through which source code is passed. This phase
include:
1. Removal of Comments
2. Expansion of Macros
3. Expansion of the included files.
August 18, 2025 17
Preprocessing
After preprocessing, filename.i is produced
August 18, 2025 18
Compilation
In this stage, the preprocessed
code is translated to assembly
instructions
After compiling, filename.s is produced
August 18, 2025 19
Assembly
During the assembly stage, an assembler is used to translate the
assembly instructions to machine code, or object code.
After assembling, filename.o is produced
August 18, 2025 20
Linking
The linker will add the object code for the built-in function and some
extra work is done here.
1. Combines all object files.
2. Resolves external references (functions/variables).
3. Links required libraries.
4. Produces the final executable file.
After linking, filename.exe is produced
August 18, 2025 21
Reference Books
1. Teach Yourself C – Herbert Schildt
2. Programming in ANSI C – E. Balagurusamy
3. Let Us C – Yashavant Kanetkar
4. C: The Complete Reference – Herbert Schildt
August 18, 2025 22