0% found this document useful (0 votes)
37 views31 pages

1b - Intro To C

The document discusses the introduction to C programming language including its history, features, uses, and programming language concepts. It covers topics like C's development, its portability, structured nature, pointers, and use in system programming. The document also provides details about compilers and interpreters.

Uploaded by

namirabushra92
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)
37 views31 pages

1b - Intro To C

The document discusses the introduction to C programming language including its history, features, uses, and programming language concepts. It covers topics like C's development, its portability, structured nature, pointers, and use in system programming. The document also provides details about compilers and interpreters.

Uploaded by

namirabushra92
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/ 31

Programming in C

Introduction to C
Ashis Talukder, PhD
Assistant Professor
Department of MIS, DU

Dr. Ashis Talukder, MIS, DU 1


Course outline
• Introduction to Principles of programming
• Introduction to Programming , Programing Domain : Scientific Application , Business
Applications, Artificial Intelligence, Systems Programming.
• Programming Languages: Machine Level Languages, Assembly Level Languages , High Level
Languages Programming.
• Design Methodologies : Top Down and Bottom UP Program Development.
• Program Execution and Translation Process.
• Problem solving using Algorithms and Flowcharts.
• Performance Analysis and Measurements: Time and Space complexity.

• Introduction to C Programming:
• Features of C and its Basic Structure.
• Simple C programs.
• Constants, Integer Constants, Real Constants, Character Constants, String Constants, Backslash
Character Constants, Concept of an Integer and Variable,
• Rules for naming Variables and assigning values to variables

Dr. Ashis Talukder, MIS, DU 2


What is C?
• The C Language is developed by Dennis Ritchie (AT&T Bell
Laboratories – 1972 ) for creating system applications that directly
interact with the hardware devices such as drivers, kernels, etc.

• C programming is considered as the base for other programming


languages, that is why it is known as mother language.

Dr. Ashis Talukder, MIS, DU 3


Features of C
• C is the widely used language. It provides many features that are given below.
• Simple
• Machine Independent or Portable
• Mid-level programming language
• structured programming language
• Rich Library
• Memory Management
• Fast Speed
• Pointers – memory, arrays
• Recursion
• Extensible
• Few keywords
• Structures, unions – compound data types

Dr. Ashis Talukder, MIS, DU 4


Features of C
• Simple
• C is a simple language in the sense that it provides a structured approach (to break
the problem into parts), the rich set of library functions, data types, etc.

• Machine Independent or Portable


• Unlike assembly language, c programs can be executed on different machines with
some machine specific changes. Therefore, C is a machine independent language.

• Mid-level programming language


• Although, C is intended to do low-level programming. It is used to develop system
applications such as kernel, driver, etc. It also supports the features of a high-level
language. That is why it is known as mid-level language.

Dr. Ashis Talukder, MIS, DU 5


Features of C
• Structured programming language
• C is a structured programming language in the sense that we can break the program
into parts using functions. So, it is easy to understand and modify. Functions also
provide code reusability.

• Rich Library
• C provides a lot of inbuilt functions that make the development fast.

• Memory Management
• It supports the feature of dynamic memory allocation. In C language, we can free the
allocated memory at any time by calling the free() function.

Dr. Ashis Talukder, MIS, DU 6


Features of C
• Speed
• The compilation and execution time of C language is fast since there are lesser inbuilt
functions and hence the lesser overhead.

• Pointer
• C provides the feature of pointers. We can directly interact with the memory by
using the pointers. We can use pointers for memory, structures, functions, array, etc.

• Recursion
• In C, we can call the function within the function. It provides code reusability for
every function. Recursion enables us to use the approach of backtracking.

Dr. Ashis Talukder, MIS, DU 7


Features of C
• Extensible
• C language is extensible because it can easily adopt new features.

• Few keywords
• C language have few keywords and thus, easy to handle and work with

• Structures, unions
• C supports compound data types like structures, unions in addition to simple
data type (int, float, char)

Dr. Ashis Talukder, MIS, DU 8


History of C
• History of C language is interesting to
know. Here we are going to discuss a brief
history of the c language.
• C programming language was developed in
1972 by Dennis Ritchie at bell laboratories of
AT&T (American Telephone & Telegraph),
located in the U.S.A.
• Dennis Ritchie is known as the founder of the c
language.
• It was developed to overcome the problems of
previous languages such as B, BCPL, etc.
• Initially, C language was developed to be used
in UNIX operating system. It inherits many
features of previous languages such as B and
BCPL.

Dr. Ashis Talukder, MIS, DU 9


History of C
• 1972 – C invented
• 1978 – The C Programming Language
published; first specification of language
• 1989 – C89 standard (known as ANSI C or
Standard C)
• 1990 – ANSI C adopted by ISO, known as
C90
• 1999 – C99 standard
• mostly backward-compatible
• not completely implemented in many
compilers
• 2007 – work on new C standard C1X
announced
Dr. Ashis Talukder, MIS, DU 10
What is C used for?
• It can be defined by the following ways:
• Mother language
• System programming language
• Procedure-oriented programming language
• Structured programming language
• Mid-level programming language

• C as a mother language
• C language is considered as the mother language of all the modern programming
languages because most of the compilers, JVMs, Kernels, etc. are written in C
language, and most of the programming languages follow C syntax, for example, C++,
Java, C#, etc.
• It provides the core concepts like the array, strings, functions, file handling, etc. that
are being used in many languages like C++, Java, C#, etc.

Dr. Ashis Talukder, MIS, DU 11


What is C used for?
• C as a system programming language
• A system programming language is used to create system software. C language is a system
programming language because it can be used to do low-level programming (for example
driver and kernel). It is generally used to create hardware devices, OS, drivers, kernels, etc.
For example, Linux kernel is written in C.
• It can't be used for internet programming like Java, .Net, PHP, etc.
• C as a procedural language
• A procedure is known as a function, method, routine, subroutine, etc. A procedural language
specifies a series of steps for the program to solve the problem.
• A procedural language breaks the program into functions, data structures, etc.
• C is a procedural language. In C, variables and function prototypes must be declared before
being used.

Dr. Ashis Talukder, MIS, DU 12


What is C used for?
• C as a structured programming language
• A structured programming language is a subset of the procedural language. Structure means
to break a program into parts or blocks so that it may be easy to understand.
• In the C language, we break the program into parts using functions. It makes the program
easier to understand and modify.
• C as a mid-level programming language
• C is considered as a middle-level language because it supports the feature of both low-level
and high-level languages. C language program is converted into assembly code, it supports
pointer arithmetic (low-level), but it is machine independent (a feature of high-level).
• A Low-level language is specific to one machine, i.e., machine dependent. It is machine
dependent, fast to run. But it is not easy to understand.
• A High-Level language is not specific to one machine, i.e., machine independent. It is easy to
understand.

Dr. Ashis Talukder, MIS, DU 13


Programming Language
• A program is a set of instructions following the rules of the chosen language.
• Without programs, computers are useless.
• A program is like a recipe.
• It contains a list of ingredients (called variables) and a list of directions (called
statements) that tell the computer what to do with the variables.
• A vocabulary and set of grammatical rules (syntax) for instructing a computer to
perform specific tasks.
• Programming languages can be used to create computer programs.
• The term programming language usually refers to high-level languages, such as
BASIC, C, C++, COBOL, FORTRAN, Ada, and Pascal.

Dr. Ashis Talukder, MIS, DU 14


Programming Language
• You eventually need to convert your program into machine language so that the
computer can understand it.
• There are two ways to do this:
• Compile the program
• Interpret the program
• Compile is to transform a program written in a high level programming language
from source code into object code.
• This can be done by using a tool called compiler.
• A compiler reads the whole source code and translates it into a complete
machine code program to perform the required tasks which is output as a new
file.

Dr. Ashis Talukder, MIS, DU 15


Programming Language
• Interpreter is a program that executes instructions written in a high-level
language.
• An interpreter reads the source code one instruction or line at a time, converts
this line into machine code and executes it.
• Computer programming is the process of writing, testing,
debugging/troubleshooting, and maintaining the source code of computer
programs.
• This source code is written in a programming language like C++, JAVA, Perl etc.

Dr. Ashis Talukder, MIS, DU 16


Programmer
• A programmer is someone who writes computer program.
• Computer programmers write, test, and maintain programs or software that tell
the computer what to do.
• What Skills are Required to Become a Programmer?
• Programming - Writing computer programs for various purposes.
• Writing - Communicating effectively with others in writing as indicated by the needs of the
audience.
• Reading Comprehension - Understanding written sentences and paragraphs in work-related
documents.
• Critical Thinking - Using logic and analysis to identify the strengths and weaknesses of
different approaches.

Dr. Ashis Talukder, MIS, DU 17


Programmer
• What Skills are Required to Become a Programmer?
• Computers and Electronics - Knowledge of electric circuit boards, processors, chips, and
computer hardware and software, including applications and programming.
• Mathematics - Knowledge of numbers, their operations, and interrelationships including
arithmetic, algebra, geometry, calculus, statistics, and their applications.
• Oral Expression - The ability to communicate information and ideas in speaking so others will
understand.
• Oral Comprehension - The ability to listen to and understand information and ideas
presented through spoken words and sentences.
• Written Expression - The ability to communicate information and ideas in writing so others
will understand.
• Written Comprehension - The ability to read and understand information and ideas
presented in writing.

Dr. Ashis Talukder, MIS, DU 18


Programmer
• What Skills are Required to Become a Programmer?
• Deductive Reasoning - The ability to apply general rules to specific problems to come up with
logical answers. It involves deciding if an answer makes sense.
• Information Organization - Finding ways to structure or classify multiple pieces of
information.

Dr. Ashis Talukder, MIS, DU 19


Generation of Programming Language
• The first generation languages, or 1GL, are low-level languages that are machine
language.
• The second generation languages, or 2GL, are also low-level languages that
generally consist of assembly languages.
• The third generation languages, or 3GL, are high-level languages such as C.
• The fourth generation languages, or 4GL, are languages that consist of statements
similar to statements in a human language. Fourth generation languages are
commonly used in database programming and scripts.
• The fifth generation languages, or 5GL, are programming languages that contain
visual tools to help develop a program. A good example of a fifth generation
language is Visual Basic.

Dr. Ashis Talukder, MIS, DU 20


Machine Language
• Low-level languages are closer to the language used by a computer, while high-level
languages are closer to human languages.
• Machine Language
• Machine language is a collection of binary digits or bits that the computer reads and interprets.
• Machine languages are the only languages understood by computers.
• While easily understood by computers, machine languages are almost impossible for humans to
use because they consist entirely of numbers.
Machine Language
169 1 160 0 153 0 128 153 0 129 153 130 153 0 131 200 208 241 96
High level language
5 FOR I=1 TO 1000: PRINT "A";: NEXT I

Dr. Ashis Talukder, MIS, DU 21


Machine Language
• Advantages of first generation language
• They are translation free and can be directly executed by the computers.
• The programs written in these languages are executed very speedily and
efficiently by the CPU of the computer system.
• The programs written in these languages utilize the memory in an efficient
manner because it is possible to keep track of each bit of data.

Dr. Ashis Talukder, MIS, DU 22


Assembly Language
• A program written in assembly language consists of a series of instructions
mnemonics that correspond to a stream of executable instructions, when
translated by an assembler, that can be loaded into memory and executed.
• Assembly languages use keywords and symbols, much like English, to form a
programming language but at the same time introduce a new problem.
• Example:
• Machine language : 10110000 01100001
• Assembly language : mov a1, #061h
• Meaning: Move the hexadecimal value 61 (97 decimal) into the processor register
named "a1".
• Assembler: masm (Microsoft Assembler), tasm (Turbo Assembler)

Dr. Ashis Talukder, MIS, DU 23


Assembly Language
• Advantages of second generation language
• It is easy to develop understand and modify the program developed in these
languages are compared to those developed in the first generation
programming language.
• The programs written in these languages are less prone to errors and
therefore can be maintained with a great case.

Dr. Ashis Talukder, MIS, DU 24


High-Level Language
• High-level languages allow us to write computer code using instructions
resembling everyday spoken language (for example: print, if, while) which are
then translated into machine language to be executed.
• Programs written in a high-level language need to be translated into machine
language before they can be executed.
• Some programming languages use a compiler to perform this translation and
others use an interpreter.
• Examples of High-level Language:
• ADA, C, C++, JAVA, BASIC, COBOL, PASCAL, PHYTON

Dr. Ashis Talukder, MIS, DU 25


High-Level Language
• Advantages of third generation programming language
• It is easy to develop, learn and understand the program.
• As the program written in these languages are less prone to errors they are
easy to maintain.
• The program written in these languages can be developed in very less time as
compared to the first and second generation language.

Dr. Ashis Talukder, MIS, DU 26


Fourth generation language (Very High-level
Languages)
• The languages of this generation were considered as very high-level
programming languages required a lot of time and effort that affected the
productivity of a programmer. The fourth generation programming
languages were designed and developed to reduce the time, cost and
effort needed to develop different types of software applications.
• Advantages of fourth generation languages
• These programming languages allow the efficient use of data by implementing the
various database.
• They require less time, cost and effort to develop different types of software
applications.
• The program developed in these languages are highly portable as compared to the
programs developed in the languages of other generation.
• Examples: SOL, CSS, coldfusion

Dr. Ashis Talukder, MIS, DU 27


Fifth generation language (Artificial
Intelligence Language)
• The programming languages of this generation mainly focus on
constraint programming. The major fields in which the fifth
generation programming language are employed are Artificial
Intelligence and Artificial Neural Networks
• Advantages of fifth generation languages
• These languages can be used to query the database in a fast and efficient
manner.
• In this generation of language, the user can communicate with the computer
system in a simple and an easy manner.
• Examples: mercury, prolog, OPS5

Dr. Ashis Talukder, MIS, DU 28


Programming Language: Comparison

Dr. Ashis Talukder, MIS, DU 29


Computer Algorithm
• An algorithm is a finite and well-defined • Finite: start, end
sequence of steps to solve a specific
problem. • Well-defined:
• Sequence:
Swap (a, b) a = 5 b = 7
{ • Steps:
temp = a; //temp = a = 5, b = 7 • Specific problem:
a = b; // temp = 5, a = 7, b = 7
b = temp; // temp = 5, a = 7, b = 5

} a=7 b=5

Dr. Ashis Talukder, MIS, DU 30


Computer Algorithm
#include<stdio.h> #include<stdio.h>
main()

main() {

{ int a,b,c;
float pi, p,q;
int a,b,c;
char aa, AA;
printf("\n\n\n\n\tProgramming is funny!");
a = 5;
b = 7;
a = 5;
b = 7;
c = a + b; c = a + b;

printf("\nSum = %d",c); printf("\nSum = %d",c);


} }

Dr. Ashis Talukder, MIS, DU 31

You might also like