You are on page 1of 26

C

Introduction to C
Programming
Chapter 1

PROGRAMMING
DEC20012 FUNDAMENTALS
MOHD ZEID ABU BAKAR
ELECTRICAL ENGINEERING DEPARTMENT
SULTAN IDRISSHAH POLYTECHNIC
OBJECTIVES
C
At the end of lesson, students should be
able :
Chapter 1 • To describe the C programming
• To explain the background of C programming
• To describe sample of C programming
• To explain the compile and execute process
• To define program, programmer &
programming language
• To describe various types of programming
languages
• To explain structured, modular & Object
Oriented programming
ZEDZ@PSIS
www.company.com
PROGRAMMING LANGUAGE ?
C

Chapter 1

ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C
• Conceptually  a framework within
which we organize our ideas about data
(object to be manipulated) and
Chapter 1
procedures ( how to manipulate the
data)
• Technically  instructions for the
computer to perform tasks

• Artificial language that can be used to


communicate instructions or to control
the behaviour & properties of a computer
& computerized devices.

ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C
• Artificial language that can be used to
control the behaviour & properties of a
Chapter 1 computer.

PROGRAMMING LANGUAGES USAGE TYPES OF LANGUAGES

- Applications
- Low Level Language @ Machine Language.
- Server
- Assembly Language
- Utilities
- High Level Language
- System Software

- Embedded System
ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C
• Low Level Languages:
• Easily understood by computers
• Difficult to understand by humans
Chapter 1
• Assembly Languages:
• Similar to the machine language
• The machine language contains numerical
information while the assembly language has
characters.

• High Level Languages:


• Used to develop complex applications
• Closer to human languages & easier to be
understood.
ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C
LOW LEVEL LANGUAGE (MACHINE
LANGUAGE)
• The only language that the processor actually
Chapter 1 'understands‘
• Consists of binary codes: 0 and 1
• Example:

• Each of the lines above corresponds to a specific task to


be done by the processor.
• Programming in machine code is difficult and slow since
it is difficult to memorize all the instructions.
• Machine dependent as it varies between different
ZEDZ@PSIS
processors (Intel, ARM & AMD)
www.company.com
THE PROGRAMMING LANGUAGE
C
ASSEMBLY LANGUAGE
• Enables machine code to be represented in words and
numbers.
Chapter 1 • Example of a program in assembler language:
LOAD A, 9999
LOAD B, 8282
SUB B
MOV C, A
LOAD C, #0002
DIV A, C
STORE A, 7002
• Easier to understand and memorize (called
Mnemonics), compared to machine code but still quite
difficult to use.
• Processor and Architecture dependent
ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C
HIGH LEVEL LANGUAGE
• Use more English words. They try to resemble English
sentences. Therefore, it is easier to program in these
Chapter 1 languages.
• The programming structure is problem oriented - does
not need to know how the computer actually executes
the instructions.
• Processor independent - the same code can be run on
different processors.
• Examples: Basic, Fortran, Pascal, Cobol, C, C++, Java
• A high level language needs to be analyzed by the
compiler and then compiled into machine code so that
it can be executed by the processor.

ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C

Chapter 1

ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C
• BASIC:
• Beginners All-purpose Symbolic Instruction
Code.
Chapter 1 • Originally designed to be simple enough for
beginners to learn.

• FORTRAN:
• Formula Translator.
• Designed for programming complex
mathematical algorithm.

• COBOL:
• Common Business-Oriented Language.
• Designed for business applications.
ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C
• Pascal:
• A structured general purpose language
designed primarily for teaching programming.
Chapter 1
• C:
• A structured, general purpose language
developed at Bell Lab which offers both high
level & low level features.

• C++:
• Based on C & offers object oriented features
not found in C.

ZEDZ@PSIS
www.company.com
THE PROGRAMMING LANGUAGE
C
• Java:
• An object-oriented language invented at Sun
Microsystem. Used to develop web based
Chapter 1 programs .

• Visual Basic:
• A Microsoft programming language & software
development environment .
• Allows programmer to quickly create Windows
based application.

ZEDZ@PSIS
www.company.com
WHAT IS C ?
C
• A high level structured & procedural
programming language.

Chapter 1 • C is an intermediate language between human


& computer.

Human Language Machine Language

• Why ‘C’? - Because based on 'B'; developed by


Dennis Ritchie at Bell Laboratories in 1972.

ZEDZ@PSIS
www.company.com
BASIC ELEMENTS OF C
C
• Semantics
• Vocabulary of commands that human can
understand and can be converted into
Chapter 1 machine language.

• Syntax
• Language structure (grammar) .

IPS!
T
Think semantics as the building blocks of your C program and
the syntax as the correct way to put them together.

ZEDZ@PSIS
www.company.com
WHAT IS A PROGRAM ?
C
• Definitions
• An organized set of instructions that tells the
computer what to do or how to do it.
Chapter 1
• Is a text file (source file) containing sequence
of C commands (semantics) put together
according to the C grammar (syntax).

ZEDZ@PSIS
www.company.com
WHAT IS A PROGRAM ?
C
• Is a text file (source file) containing
sequence of C commands (semantics)
put together according to the C grammar
Chapter 1
(syntax).
IPS!
T
Think program as a recipe which contains a list of ingredients &
a list of direction.

.
e.g
a word processor is a program written in computer language like C,
that tells the computer what to do when you type in a letter.

ZEDZ@PSIS
www.company.com
COMPILING & BUILDING?
C
• Compiling is the act of turning source
code into object code.
Chapter 1
• Linking is the act of combining object
code with libraries into a raw executable
program .

• Building is the sequence composed of


compiling and linking processes.
IPS!
T
Building = Compiling + Linking

ZEDZ@PSIS
www.company.com
UNDERSTANDING BUILDING PROCESS
C Remove comments
Source code (.c file)
Include header files
Replace macro with Preprocessor

Compiling Process
code
Chapter 1 Compiler
Generate assembly code (.s file)
Building Process

Assembly Code

Assembler
Generate object code (.obj file)
Linking Process

Libraries Object Code

Linker
Generate executable file (.exe file)
Components of
compiler
Executable file
ZEDZ@PSIS
www.company.com
PROGRAMMER ?
C
• A programmer is a person who designs,
writes & test computer programs.
Chapter 1

ZEDZ@PSIS
www.company.com
STRUCTURED PROGRAMMING
C

TYPES OF PROGRAMMING

Structured programming takes on the top


Chapter to bottom approach.
1

ZEDZ@PSIS
www.company.com
MODULAR PROGRAMMING
C

TYPES OF PROGRAMMING

Program is broken into smaller


Chapter independent unit called modules
according to its functionality and each
1
module is developed independently of
each other.

ZEDZ@PSIS
www.company.com
OBJECT ORIENTED PROGRAMMING
C

TYPES OF PROGRAMMING

OOP splits the program into objects that


Chapter can be reused into other programs.
1 • Each function is developed to instruct an
object to perform actions based on the
event that take place.

ZEDZ@PSIS
www.company.com
WHAT IS AN IDE?
C

Chapter 1
editor

compiler

IPS!
T
Development tools that combine both editor and compiler is
called development Integrated Development Environment , IDE.
www.company.com
SAMPLE OF C PROGRAM
C

Chapter 1

ZEDZ@PSIS
www.company.com
CREATING YOUR 1st C PROGRAM
C

Chapter 1 Step 1 Entering the C code

Step 2 Building the program

Step 3 Executing the program

ZEDZ@PSIS
www.company.com

You might also like