0% found this document useful (0 votes)
80 views43 pages

L02 - Introduction To C

This document provides an overview of structured programming using the C language. It discusses the software development life cycle, programming paradigms including structured/procedural programming, and elements of structured programming like control structures and subroutines. It then introduces C as a structured programming language, covering its history, applications, development cycle, and environment. An example C program is also provided to demonstrate the basic structure and syntax of a C program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views43 pages

L02 - Introduction To C

This document provides an overview of structured programming using the C language. It discusses the software development life cycle, programming paradigms including structured/procedural programming, and elements of structured programming like control structures and subroutines. It then introduces C as a structured programming language, covering its history, applications, development cycle, and environment. An example C program is also provided to demonstrate the basic structure and syntax of a C program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 43

CSE-141: Structured Programming

 Lecture 02: Introduction to Structured Programming


Instructor
Md. Sabir Hossain
Lecturer
Dept. of CSE, CUET
Mobile: 01737143868/01882826575
Email: [email protected]

Acknowledgment: Most of the content of this slide is adopted from different books and internet
Recap
• Software Development Life Cycle
• Definition: Computer Programming
• Programming Paradigms
– The imperative paradigm (Structured/Procedural Programming)
– The functional paradigm
– The logical paradigm
– The object-oriented paradigm
• Structured Programming Basic
• Elements of Structured Programming
– Control Structures, Subroutines and Blocks
• Comparative Study of Programming Paradigms
Software Development Life Cycle

https://online.husson.edu/software-development-cycle/
Languages by Paradigm
• Imperative (also called Structured or
Procedural) Programming
– FORTRAN, BASIC, COBOL, Pascal, C
• Object-Oriented Programming
– SmallTalk, C++, Java
• Functional Programming
– LISP, ML, Haskell
• Logic Programming
– Prolog, CHIP (programming language), Ciao
(programming language), CLACL, CycL
Differences
• Difference among Procedural, Structural and Object
Oriented Programming languages

http://www.differencebetween.info/difference-between-procedural-structural-and-object-oriented-programming-languages
Outlines
• Programming Languages
• Categories
• Translators: Compiler Vs Interpreter
• What is C?
• Application-Why Use C?
• History of C
• The C Development Cycle
• C Compilation Environment
• An Example of C Program

6
Learning Outcomes
• At the end of the lecture students will able to
– Distinguish among different categories of
Programming Languages
– Explain the working procedure of different translators
– Explain the history, features, applications of C
Programming Language
– Understand the C Program development cycle
– Write program in C language
Programming Languages
Evolution of Prog. Lang

http://www.digibarn.com/collections/posters/tongues/ComputerLanguagesChart-med.png
Categories
Programming Languages
• There are three categories of programming
languages:
– Machine languages
– Assembly languages
– High-level languages
• Machine languages and assembly languages
are also called low-level languages
• Some understandable directly by computers
• Others require “translation” steps (Translator)
Language Translators
Machine language
• A Machine language program consists of a
sequence of zeros and ones.
– Each kind of CPU has its own machine language
– E.g. Add var1 and var2 and store result in var1
• Advantages
– Fast and efficient 8086 Machine language program for
– Machine oriented var1 = var1 + var2 ;
– No translation required 1010 0001 0000 0000 0000 0000
0000 0011 0000 0110 0000 0000 0000 0010
1010 0011 0000 0000 0000 0000
• Disadvantages
– Not portable
– Not programmer friendly
Assembly Language
• Assembly language programs use
mnemonics to represent machine instructions

• Each statement in assembly language


corresponds to one statement in machine
language

• Assembly language programs have the same


advantages and disadvantages as machine
language programs.
Assembly Language
• Translators programs called “Assemblers” to
convert assembly language programs to
machine language.
• Compare the following machine language and
assembly language programs:
8086 Machine language program for 8086 Assembly program
var1 = var1 + var2 ; for
var1 = var1 + var2 ;
1010 0001 0000 0000 0000 0000 MOV AX , var1
0000 0011 0000 0110 0000 0000 0000 0010 ADD AX , var2
1010 0011 0000 0000 0000 0000 MOV var1 , AX
High-Level Programming
Languages
• To speed up programming even further
• Single statements for accomplishing substantial
tasks
• Translator programs called “Compilers”/
“Interpreter” to convert high-level programs into
machine language
• A HLL language program consists of English-
like statements that are governed by a strict
syntax.
High-Level Programming
Languages
• A high-level language (HLL) has two primary
components
– (1) a set of built-in language primitives and
grammatical rules
– (2) a translator (Compiler/Interpreter)
• Examples : C, C++, Java, FORTRAN, Visual
Basic, and Delphi.
High-Level Programming
Languages
• Advantages
– Portable or machine independent
– Programmer-friendly
• Disadvantages
– Not as efficient as low-level languages
– Need to be translated
Where you are?
What is C?
 C
 A language written by Brian Kernighan
and Dennis Ritchie.
 This was to be the language that UNIX
was written in to become the first
"portable" language

In recent years C has been used as a general-


purpose language because of its popularity with
programmers.
History of C at a glance
History
• In 1972 Dennis Ritchie at Bell Labs writes C
and in 1978 the publication of The C
Programming Language by Kernighan &
Ritchie caused a revolution in the computing
world

• In 1983, the American National Standards


Institute (ANSI) established a committee to
provide a modern, comprehensive definition of
C. The resulting definition, the ANSI standard, or
"ANSI C", was completed late 1988.
History of C
• Evolved from two previous languages
– BCPL , B
• BCPL (Basic Combined Programming Language)
used for writing OS & compilers
• B used for creating early versions of UNIX OS
• Both were “typeless” languages
• C language evolved from B (Dennis Ritchie – Bell
labs)

** Typeless – no datatypes. Every data item occupied 1 word in memory.


History of C
• Hardware independent
• Programs portable to most computers
• Dialects of C
– Common C
– ANSI C
• ANSI/ ISO 9899: 1990
• Called American National Standards Institute ANSI C
• Case-sensitive
Features of C
Application - Why use C?
• Mainly because it produces code that runs
nearly as fast as code written in assembly
language. Some examples of the use of C might
be:
– Operating Systems
– Language Compilers
– Assemblers
– Text Editors
– Print Spoolers
– Network Drivers
– Modern Programs
– Data Bases
– Language Interpreters
– Utilities

Mainly because of the portability that writing standard C


programs can offer
Why C Still Useful?
• C provides:
– Efficiency, high performance and high quality s/ws
– flexibility and power
– many high-level and low-level operations  middle
level
– Stability and small size code
– Provide functionality through rich set of function
libraries
– Gateway for other professional languages like C  C+
+  Java
Why C is Middle Level Language ?
Why C is Middle Level Language ?
Why C is Middle Level Language ?
• C Programming Supports Inline Assembly Language
Programs
• Using inline assembly language feature in C we can
directly access system registers
• C Programming is used to access memory directly using
pointer
• Combines features of high level language and
functionality of assembly language
• Well suited for writing both application software and
system software
C Standard Library
• Two parts to learning the “C” world
– Learn C itself
– Take advantage of rich collection of existing functions
called C Standard Library
• Avoid reinventing the wheel
• Software reusability
The C Development Cycle

Edit
Program

Source
Code

Compile

Object
Code

Library Link Object


Files Code Executable
Basics of C Environment
• Development environment has 6 phases
– Edit
– Pre-processor
– Compile
– Link
– Load
– Execute
Basics of C Environment

Program edited in
Phase 1 Editor Disk Editor and stored
on disk
Preprocessor
Phase 2 Preprocessor Disk program processes
the code
Creates object code
Phase 3 Compiler Disk and stores on disk

Links object code


Phase 4 Linker Disk with libraries and
stores on disk
Basics of C Environment
Primary memory
Puts program in
Phase 5 Loader memory

Primary memory
Takes each instruction
Phase 6 CPU and executes it storing
new data values
Simple C Program
/* A first C Program*/

#include <stdio.h>

void main()

{
     printf("Hello World \n");

}
Simple C Program
• Line 1: #include <stdio.h> /* A first C Program*/

#include <stdio.h>
• As part of compilation, the C compiler runs
void main()
a program called the C preprocessor. The
preprocessor is able to add and remove {
code from your source file. printf("Hello World \n");

• In this case, the directive #include tells }


the preprocessor to include code from the
file stdio.h.
• This file contains declarations for functions
that the program needs to use. A
declaration for the printf function is in this
file.
Simple C Program
• Line 2: void main() /* A first C Program*/

#include <stdio.h>
• This statement declares the main
void main()
function.
{
• A C program can contain many functions
printf("Hello World \n");
but must always have one main function.
• A function is a self-contained module of }

code that can accomplish some task.


• Functions are examined later.
• The "void" specifies the return type of
main. In this case, nothing is returned to
the operating system.
Simple C Program
• Line 3: { /* A first C Program*/

#include <stdio.h>

• This opening bracket denotes void main()

the start of the program. {


printf("Hello World \n");

}
Simple C Program
• Line 4: printf("Hello World From /* A first C Program*/

About\n");
#include <stdio.h>

• Printf is a function from a standard C library void main()

that is used to print strings to the standard {


output, normally your screen. printf("Hello World \n");
• The compiler links code from these standard
}
libraries to the code you have written to
produce the final executable.
• The "\n" is a special format modifier that
tells the printf to put a line feed at the end of
the line.
• If there were another printf in this program,
its string would print on the next line.
Simple C Program
• Line 5: } /* A first C Program*/

• This closing bracket denotes #include <stdio.h>

the end of the program. void main()

{
printf("Hello World \n");

}
Thank You
• Allah Hafez

You might also like