Computer programming
By
DR. DEVANSHU TIWARI
Assistant Professor
Centre for Computer Science & Technology
MITS, Gwalior
Friday, August 22, 2025
Unit –I
Introduction to Programming: Machine Level Languages,
Assembly Level Languages, High Level Languages, Program,
Program Execution & Translation Process, Problem solving using
Algorithms and Flowcharts.
Introduction to C++ Programming: Data Types, Constants,
Keywords, Operators & Expressions, Precedence of operators
and input/output functions.
Friday, August 22, 2025
Programming Language
A programming language is a sequence of
statement and syntax used to create software
programs.
Syntax: The specific rules and structure used
to write code in a programming language.
A computer program (also software, or just a
program) is a sequence of statement written to
perform a specified task with a computer.
Friday, August 22, 2025
Why do we need
programming
language?
❑ Computer can’t understand English language
❑ Human can’t easily write binary or machine
language
Computers do not understand human language,
so people use programming languages to
translate directions into binary code that
computer devices can follow as apps, websites,
and software programs.
Friday, August 22, 2025
What is a Computer
Program?
Some common and popular definitions
● A computer program is a set of instructions that are written to perform a
task again and again.
● A computer program is a set of instructions that are written to solve a
problem.
● A computer program is a set of instructions written in a programming
language that a computer can execute to perform a specific task or solve
a problem.
● A computer program is an executable file that directs the computer to
perform a series of operations, such as processing data, performing
calculations, or interacting with other software and hardware.
What is a Computer Program?
Technically correct definition
● A computer program is not at all set of instructions that are
written to perform a task again and again.
● A computer program is a sequence of statements that are
written to perform a task again and again.
● A computer program is a sequence of statements that are
written to solve a problem.
Why ?
What is a Computer Program?
Because use of two words primarily making the earliers definitions wrong.
● Mathematically a Set is an unordered collection of elements for eg:
A = {1,2,3,4} is equal to or same as A = {2,1,3,4}
But in a computer program, if we change the sequence of statements then the
output will not be same or error comes. So the use of word “Set” is technically
wrong.
● Whereas the word “instructions” are primarily used when we are directly
working on the processor. But in this scenario we are writing a computer
program using a programming language so the word “statements” are more
appropriate.
Lets take an another example
What is a Computer Program?
Example 1: Correct Order Example 2: Incorrect Order
# Correct Order # Incorrect Order
x = 10 x = 10
y=5
y=5
# Print before performing the addition
# Addition first, then print print("Result:", result) # This will cause an
result = x + y error
print("Result:", result) result = x + y
Output:
Output: Error
Result: 15 NameError: name 'result' is not defined
Generation of Programming Languages
Friday, August 22, 2025
1. First-Generation Language : The first-generation
languages are also called machine languages/ 1G
language. This language is machine-dependent. The
machine language statements are written in binary
code (0/1 form) because the computer can understand
only binary language.
Advantages :
1. Fast & efficient as statements are directly written in
binary language.
2. No translator is required.
Disadvantages :
1. Difficult to learn & Remember binary codes.
2. Difficult to understand – both programs & where
the error occurred.
Friday, August 22, 2025
2. Second Generation Language :
The second-generation languages are also called assembler languages/ 2G languages.
Assembly language contains human-readable notations (mnemonic code) that can be
further converted to machine language using an assembler.
Assembler – converts assembly level instructions to machine-level instructions.
Programmers can write the code using symbolic instruction codes that are meaningful
abbreviations of mnemonics. It is also known as low-level language.
Advantages :
1. It is easier to understand if compared to machine language.
2. Modifications are easy.
3. Correction & location of errors are easy.
Disadvantages :
1. Assembler is required.
2. This language is architecture /machine-dependent, with a different instruction set
for different machines.
Friday, August 22, 2025
Friday, August 22, 2025
3. Third-Generation Language :
The third generation is also called procedural language /3 GL. It consists of the use of a
series of English-like words that humans can understand easily, to write instructions. It’s also
called High-Level Programming Language. For execution, a program in this language needs
to be translated into machine language using a Compiler/ Interpreter. Examples of this type
of language are C, PASCAL, FORTRAN, COBOL, etc.
Advantages :
1. Use of English-like words makes it a human-understandable language.
2. Lesser number of lines of code as compared to the above 2 languages.
3. Same code can be copied to another machine & executed on that machine by using
compiler-specific to that machine.
Disadvantages :
1. Compiler/ interpreter is needed.
2. Different compilers are needed for different machines.
Friday, August 22, 2025
Friday, August 22, 2025
4. Fourth Generation Language :
The fourth-generation language is also called a non – procedural language/
4GL. It enables users to access the database. Examples: SQL, Foxpro ,
Focus, etc.
These languages are also human-friendly to understand.
Advantages :
1. Easy to understand & learn.
2. Less time is required for application creation.
3. It is less prone to errors.
Disadvantages :
1. Memory consumption is high.
2. Has poor control over Hardware.
3. Less flexible.
Friday, August 22, 2025
5. Fifth Generation Language :
The fifth-generation languages are also called 5GL or natural language
programming (NLP). It is based on the concept of artificial intelligence. It uses
the concept that rather than solving a problem algorithmically, an application
can be built to solve it based on some constraints, i.e., we make computers
learn to solve any problem. Parallel Processing & superconductors are used for
this type of language to make real artificial intelligence.
Examples: PROLOG, LISP, etc.
Advantages :
1. Machines can make decisions.
2. Programmer effort reduces to solve a problem.
3. Easier than 3GL or 4GL to learn and use.
Disadvantages :
1. Complex and long code.
2. More resources are required & they are expensive too.
Friday, August 22, 2025
Program execution & transition
Program execution is the process of running a computer program, while program transition is
the process of moving a program from one state to another
❑ Source code is a sequence of instructions written by programmer using programming
language.
❑ Preprocessor programs provide preprocessor directives that tell the compiler to preprocess
the source code before compiling. All of these preprocessor directives begin with a ‘#’
(hash) symbol. The ‘#’ symbol indicates that whatever statement starts with a ‘#’ will go to
the preprocessor program to get executed. We can place these preprocessor directives
anywhere in our program.
Examples of some preprocessor directives are: #include, #define, #ifndef, etc.
Friday, August 22, 2025
❑ Compiler is a translator that takes input i.e., High-Level Language, and produces an
output of low-level language i.e. machine or assembly language. The work of a Compiler
is to transform the codes written in the programming language into machine code (format
of 0s and 1s) so that computers can understand.
❑ Assembler is used to translate the program written in Assembly language into machine
code. The source program is an input of an assembler that contains assembly language
instructions. The output generated by the assembler is the object code or machine code
understandable by the computer.
Friday, August 22, 2025
High-Level Language Source code
(.c,.cpp,.h )
Preprocessor
Preprocessed file (.i file)
Compiler
Assembly code (.s file)
Assembler
Object code (.o file)
Loader/Linker
Executable machine code (.exe file)
Low-Level Language Machine code
Friday, August 22, 2025
❑A linker is a computer program that joins one or more object files generated by a
compiler into a single executable, library, or other object files.
❑A loader is a computer program that loads an executable file into memory, prepares it for
execution, and starts its execution.
❑Machine language is the lowest level of programming language that directly corresponds
to the instructions executed by a computer's hardware. It consists of a series of binary
numbers that represent specific instructions and data.
Friday, August 22, 2025