KEMBAR78
Lec 1 | PDF | Programming | Computer Program
0% found this document useful (0 votes)
6 views24 pages

Lec 1

Uploaded by

aaditya.kv1udr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views24 pages

Lec 1

Uploaded by

aaditya.kv1udr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Dr.

Supriyo Mandal,
Fundamental of Computer Programming Ph.D. (IIT Patna)
Postdoc (ZBW, University of Kiel,
Germany)
Course code: (CSE-1003) (L-T-P-Cr: 2-1-2-4)
Course Name: Fundamental of Computer Programming

Credits –4
https://iiitbhopal.ac.in/Document/ss/CSE-1003.html
Evalution Policy Theory
Component Marks
Class test/Quiz 20
Course MidTerm 20
Evaluation
Policy EndTerm 60
Total 100
Evalution Policy Lab
Component Marks
Class performance/Assignment 20
Course Class performance/Assignment 20
Evaluation
Policy EndTerm 60
Total 100
What is a computer program?

A set of instructions that is given to a computer to achieve some particular tasks.


There are two types of programming languages:-

1) High level languages


2) Low level languages
High Level Language (HLL)

1. Easy to understand
2. Easy to write
3. Easy fixing
4. Often platform independent/machine independent
5. These are primary choices of programming

E.g. print(“Hello World!!”)


Python, java, c, c++
Low Level Language (LLL)

1. Difficult to understand
2. Difficult to write
3. Difficult to debug
4. Not portable
5. Machine dependent
6. Primary choices for machine programming
7. Comparatively fast

Eg: Assembly language, machine code....


100100 011100
Classification of languages
According to the extent of translation needed to generate
the machine instruction from the program

High level language Low level language

1. More close to machine


1. Easily understandable, (either machine language
more like English. or assembly language).
2. Need to be translated 2. Does not require translator
/compiled before it gets or processor as they are
executed. very close to native
3. Machine independent, language of the computer
portable 3. Machine dependent, not
portable
C Program

● general-purpose programming language


● created by Dennis Ritchie
● the Bell Laboratories in 1972.
What is algorithm

ØProgram = Algorithm + Data


ØEffective procedure for solving a problem in a finite number of
steps.
ØIt also terminates (ends).
ØEffective = answer is found
ØDifferent ways of stating algorithm
ØStep form : statements to follow in steps
ØPseudo Code : English form with restricted vocabs
ØFlowchart
Simple Algorithm : pseudo-code

•Begin.
•WRITE “Please enter two numbers to add”
•READ num1.
•READ num2.
•Sum = num1+num2.
•WRITE Sum.
•End.
Simple Algorithm : flow chart

Is Ans=
Computer ?
Simple Algorithm : flow chart

Output
3
5
7
Translator, linker loader

ØTranslator : three types


ØAssembler (assembly language to machine language)
ØCompiler (translates the source to object code at once)
ØInterpreter (translates each line of source code, slower)

Depending on implementation , high level language uses


either compiler or interpreter(Basic) o both (Java).

§ For debugging, interpreted language is better than compiled language.


§ Java uses both compiler and interpreter
Translator, linker loader
ØLinker
ØHigh level language provides libraries so that certain common
operation can be reused.
ØIn C, all subprograms and common variables need to be linked
to form an useful execution unit (they were separately
translated as different units)
ØLinking makes the address of the programs known to each
other or to the main program so that transfer of control from
one point to another takes place during execution.
Translator, linker loader
ØLoader
ØBrings program from secondary memory to primary memory (RAM –
ROM).
ØSo that it can run. Initiates execution.
ØEx : Bootstrap loader is an absolute loader which is executed when
computer is switched on or restarted.
ØThe main program is loaded into main memory and gets executed.
When a function or subroutine is called, checks if it is already loaded is
not then loads into the memory.
ØRandom memory allocation happens depending on availability but the
memory addresses are updated in program’s address tables.
Compiler vs (/ Interpreter)

● C is a compiler based programming language.


● It lists all the errors at once. (/does not stop at any error in line)
● Scans the code completely. (/ execute line by line)
● Creates an intermediate object code (/directly executed by the interpreter)
WHY c?
ØC is a core language - C is considered the grandfather of most modern programming
languages, and if you have a strong foundation in C, you can apply the concepts in C to
those higher level languages.
ØBlock structured, procedural, imperative, cross platform
ØC forces you to build a mental model of what the computer is actually doing when you run
your programs
ØQuite simple to get started.
ØC is a small language : It has less data type, only 32 keywords (20 common use, like case ,
break, double, int etc)
ØC is quick : program runs quickly, very close to the hardware. Can avail low level facilities
without affecting run time.
ØC is portable : program written on one system can run with little or no modification on
other system. If modifications needed, a few changes in header file is required.
Developing program in c

1. Writing the program :


• use text editor or an IDE (Integrated Development
Environment)
• Save file with .c extension
2. Compiling the program – details in next page
3. Executing program –
1. Each statement is sequentially executed.
2. If program requests data from user, waits for input.
3. Or program can wait for an event like mouse click.
4. Results or output displays on the screen
5. Results can also be stored in a file.
Compiling a c program – four steps

Step-1 Preprocessing

ØIt processes include files, conditional compiler instructions and


macros
ØPreprocessor directives are there in the source code which
specifies instructions on how to modify the source code

Step-2 Compilation

ØGenerates the assembly source code


ØChecks syntaxes and semantics, generates error. Program has to
be recompiled.
Compiling a c program – four steps

Step-3 Assembly

Takes assembly code and generates object code (binary format)


Object code is written into another file on the system
filename.c filename.o

Step-4 Linking

ØPurpose of linking phase is to get the program in final form for


execution.
ØThe functions are part of standard C library, provided in C compiler
Compiling a c program – example

#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
Error

Ø Compilation error
§ Given by compiler and prevent program from running

Ø Linking error
§ Given by linker or at run time
§ If part of program is missing or non existent library component

Ø Run time error


Ø Given by operating system
Linux commands

#include <stdio.h>
ls
int main()
pwd
{
mkdir <C_lab>
printf("Hello, World!");
cd C_lab
return 0;
touch Cprog1.c
}
cp Cprog1.c Cprog2.c
mv <Cprog2.c> </home/kiit/prog>
rm <filename>
rmdir <directory name> compile: gcc hello.c or gcc hello.c -o h1
vi Cprog1.c run: ./a.out or ./h1
write something and :wq

You might also like