Imperative Programming
Imperative Programming
UNIT 1
Types of computer programming languages
There are basically three types of computer programming languages, they are
• Earlier computers had fixed programs: they were hardwired to do one thing.
• Sometimes external programs were implemented with paper tape or by setting
switches.
• First imperative languages: assembly languages
• 1954-1955: Fortran (FORmula TRANslator)
John Backus developed for IBM 704
• Late 1950’s: Algol (ALGOrithmic Language)
• 1958: Cobol (COmmon Business Oriented Language) Developed by a government
committee; Grace Hopper very influential.
• The earliest imperative languages were the machine languages of the original
computers.
• In these languages, instructions were very simple, which made hardware
implementation easier, but hindered the creation of complex programs.
• Advantage: • Disadvantage:
• Very simple to implement • Complex problem cannot
• Better encapsulation be solved
• Bugs free code • Less efficient and less
• It contains loops, variables productive
etc. • Parallel programming is not
possible
• Step 1: Start
• Step 2: Declare variables num1, num2 and sum.
• Step 3: Read values num1 and num2.
• Step 4: Add num1 and num2 and assign the result to sum.
• sum←num1+num2
• Step 5: Display sum
• Step 6: Stop
• START
• Input Length of Rectangle as L
• Input Breadth of Rectangle as B
• Calculate Area= L * B
• Print Value of Area
• END / STOP
• Terminator
A diamond represents a decision or branching point. Lines coming out from the
diamond indicates different possible situations, leading to different sub-
processes.
• Data
• #include <stdio.h>
• int main()
• {
• // printf() displays the string inside quotation
• printf("Hello, World!");
• return 0;
• }
int main()
{
int a, b, c;
c = a + b;
return 0;
}
• Let's try to understand the flow of above program by the figure given below.
• 1) C program (source code) is sent to preprocessor first. The preprocessor is
responsible to convert preprocessor directives into their respective values.
The preprocessor generates an expanded source code.
• 2) Expanded source code is sent to compiler which compiles the code and
converts it into assembly code.
• 3) The assembly code is sent to assembler which assembles the code and
converts it into object code. Now a simple.obj file is generated.
• 4) The object code is sent to linker which links it to the library such as header
files. Then it is converted into executable code. A simple.exe file is
generated.
• 5) The executable code is sent to loader which loads it into memory and
then it is executed. After execution, output is sent to console
Character Set
Uppercase A-Z
1. Letters
Lowercase a-z
2. Digits All digits 0-9
All Symbols: , . : ; ? ' "
3. Special Characters ! | \ / ~ _$ % # & ^ * -
+<>(){ }[]
Blank space,
Horizintal tab,
4. White Spaces
Carriage return, New
line, Form feed
C Keywords
auto double int struct
break else long switch
case enum register typedef
char extern return union
continue for signed void
do if static while
default goto sizeof volatile
const float short unsigned
void As the name suggests, it holds no value and is generally used for
specifying the type of function or what it returns. If the function
has a void type, it means that the function will not return any
value.
Pointers These are powerful C features which are used to access the
memory and deal with their addresses.
Union These allow storing various data types in the same memory
location. Programmers can define a union with different
members, but only a single member can contain a value at a
given time. It is used for
#include <stdio.h>
int main()
{
int a;
float b;
double c;
char d;
printf("Size of int=%lu bytes\n",sizeof(a));
printf("Size of float=%lu bytes\n",sizeof(b));
printf("Size of double=%lu bytes\n",sizeof(c));
printf("Size of char=%lu byte\n",sizeof(d));
return 0;
}
> Checks if the value of left operand is greater than (A > B) is not true.
the value of right operand. If yes, then the
condition becomes true.
< Checks if the value of left operand is less than the (A < B) is true.
value of right operand. If yes, then the condition
becomes true.
>= Checks if the value of left operand is greater than (A >= B) is not true.
or equal to the value of right operand. If yes, then
the condition becomes true.
<= Checks if the value of left operand is less than or (A <= B) is true.
equal to the value of right operand. If yes, then the
condition becomes true.
• int main()
• {
• int age;
• return 0;
• }