This document provides an introduction to the C programming language. It discusses the evolution of C from earlier languages like BCPL and B. C is described as a mid-level, structured programming language that is widely used and gives good machine efficiency while also being understandable by programmers. The document also defines key concepts like algorithms, flowcharts, pseudocode, ASCII/scan codes, and the differences between compilers and interpreters. It provides examples and questions to help learn about programming in C.
1. Introduction to Programming & C
Md. Rakibuzzaman Khan Pathan
Lecturer, CSE Dept.
City University, Bangladesh.
CSE-113: Structured Programming Language
2. Learning Objectives
• Programming Language.
• Level of Programming Language.
• Evolution of C.
• Algorithm, Flowchart ,Pseudo Code, ASCII & Scan code.
• Compiler & Interpreter.
3. What is Programming Language
• A set of instructions and data are together said a program.
• A programming language is a set of rules that provides a way of telling
a computer what operation to perform.
• This program may be designed using any of the computer languages
by a programmer.
• This program is not directly understood by the computer machine.
Therefore, compiler or interpreter is used to translate the
programmers code into a code that is understood by the computer.
4. Level of Programming Languages
• Low-level Language.
a) Most basic(Machine-level) language.
b) These languages are very similar to the machine code.
c) Collection of very detailed instruction set.
d) Controls computer’s internal circuitry.
e) Very difficult to understand and implementation for general user.
f) Offer better machine efficiency.
Example: Assembly language, Machine Language.
5. Level of Programming Languages
• High-Level Language.
a) Easily to understand by general users.
b) Very similar to the human language.
c) Program must be translated into machine code before execution.
d) Offer better programming efficiency
Example: Pascal, C, Java, Basic etc.
6. Procedural Programming VS Structured Programming
• Procedural: Generally flows from one statement to the next, with
occasional jumps and loops handled with goto statements. As the
amount of code and complexity increases, the end result is code that
is extremely difficult to read and maintain, known as spaghetti code.
Assembly language and the resultant machine code are both
examples of procedural languages.
• Structured :Introduces looping structures (for, while, do…while) with
orderly breaks, and procedure calls which allow code to branch and
return to the caller, rather than simply jump to arbitrary code never
to return. There is much less need for goto statements which
ultimately makes code that much easier to read and easier to
maintain.
7. Why is C called a structured programming language?
• C is called a structured programming language because to solve a
large problem, C programming language divides the problem into
smaller modules called functions or procedures each of which
handles a particular responsibility. The program which solves the
entire problem is a collection of such functions.
8. Evolution of C
1960 COBOL, FORTRAN:
Problem: They were for special purpose. Such as COBOL for commercial
field and FORTRAN for engineering solution.
1960: People started to think to develop such a language which can
apply for all the possible application rather than so many language. For
this purpose, an international committee was set up.
They come out with a new language called ALGOL 60.
Problem: ALGOL 60 was too abstract and too general.
9. Evolution of C
1963 : Another new language called CPL(Combined Programming Language)
was developed at Cambridge University.
Problem: Hard to learn and very difficult to implement.
1967: Martin Richard developed another language, called BCPL(Basic
Combined Programming Language).
Problem: Less powerful and too specific.
1970: Around this time, a language called B was written by Ken Thompson at
AT&T Bell Labs.
Problem: Also specific as BCPL.
1972: Denis Ritchie at AT&T Bell Labs inherited the features of BCPL and B
with some other new features from his own and developed C language.
10. Why Learn C
• Compact, fast and powerful.
(Compact- consisting of parts that are positioned together closely or in a tidy way, using very little space).
Structured programming language – a disciplined approach to write programs that are clear and easily modified.
“Mid-level” language.
[High level language have been designed to give a better programming efficiency, where the low-level languages give good
machine efficiency.
C gives both. For this reason, C is often called a Middle-level language.]
Standard for program development.
Useful for all applications.
C is the native language of UNIX.
Friendly, reliable, simple and easy to use.
Support Modular Programming style.
11. Algorithm
Algorithm: An algorithm is a set of rules or steps to solve a mathematical problem
or a computer program. Algorithm describes how people realize a problem, find a
right way to solve it, analyze the data, make an optimal solution and finally output
the result.
Properties of good algorithm :
1) It should be as simple as possible.
2) Steps must be unambiguous so that computer understands the steps properly.
3) It should be understood by others.
4) It must be effective to solve the required problem.
5) It should be able to find an optimal solution.
6) It should have the capability to handle some unexpected situation during
problem solving.
12. Algorithm
Example: You are given the value of radius of a circle. Find its area.
1. Input radius.
2. If radius is less than 1, then go to step 1.
3. Calculate area: area= 3.14159*radius*radius.
4. Print the value of area.
5. Stop.
13. Flowchart
Flowchart:
A flowchart(also called “flow diagram” or “flow sheet”) is a diagram
which graphically describe the movement or action of a complex
activity. It is called a flowchart since it charts the flow of a program.
Some specified graphical shapes(such as rectangle, oval, diamond etc.)
are used to represent a flowchart.
16. Pseudo code
Pseudo code:
Pseudo code is an alternative of flowchart. It allows the
programmer to describe the solution of a problem which may look
plain English. The reason for pseudo code is to represent the solution
to anybody without programming difficulties. As it is easy to implement
and understand. Many programmer’s represent their solution using
pseudo code, rather than flowchart.
18. ASCII & Scan code
ASCII code: ASCII stands for American Standard Code for Information
Interchange. Computers can only understand numbers, so an ASCII
code is the numerical representation of a character such as 'a' or '@'
etc.
This code is basically used for identifying characters and numerals in a
keyboard. these are 8 bit sequence code and are used for identifying
letters, numbers and special characters.
20. Scan code
Scan code: When we press a key from the keyboard, the PC keyboard
does not generate the ASCII code for that character. Instead, each time
a key is pressed, the keyboard generates a value that corresponds to
that key’s position. This value is called scan code. By generating scan
codes, instead of ASCII code, it is possible for the operating system to
translates those codes into any form it needed.
All the keys of the keyboard has a unique scan code. But, there are
several keys which has no ASCII value.
21. Compiler and Interpreter
A compiler or Interpreter is a code converter used to convert our hand-
written program (source code) into a corresponding machine
code(object code). Each of the computer languages has its own
Compiler or Interpreter.
Main difference between Compiler and Interpreter is that, Compiler
translates the entire program into machine code and then begin to
execute its instruction. But the interpreter translates each instruction
before execute it.
23. Questions
1) Briefly describe the importance of C.
2) What is an algorithm? Write the properties of a good algorithm.
3) Why C is called “Mid-level” language?
4) What do you mean by ASCII code and Scan code?
5) What is a flowchart? Describes the symbol of flowchart.
6) What is pseudo code?
7) Difference between Compiler and Interpreter.
24. Questions
From the following, which one is correct and which one is wrong .If wrong,
why?
1. C is a good example of low-level language.
2. High-level language are easily understandable to general users.
3. C is a special purpose language.
4. C is the most widely used programming language in the world.
5. C provides full control to the programmer and makes him independent.
6. C use interpreter to convert user program into machine code.
7. C is a case sensitive language.
25. Fill in the blanks
1. A computer program is consists of a …… and ……
2. ….. is a statement that specifies an operation to be performed by a
system.
3. …… language are most basic or machine level languages.
4. C was developed by …… at AT&T Bell Labs in …….
5. C was developed inheriting the features of previous two languages
called …… and ……