L02 - Introduction To C
L02 - Introduction To C
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
Edit
Program
Source
Code
Compile
Object
Code
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
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");
#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 }
#include <stdio.h>
}
Simple C Program
• Line 4: printf("Hello World From /* A first C Program*/
About\n");
#include <stdio.h>
{
printf("Hello World \n");
}
Thank You
• Allah Hafez