0% found this document useful (0 votes)
13 views

Lecture 4 C Programming

Uploaded by

Ibrahim Wael
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Lecture 4 C Programming

Uploaded by

Ibrahim Wael
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

‫كلية تكنولوجيا الصناعة والطاقة‬

PEARSON BTEC International Standards Verifier


ICT Program
q
Programming Essentials in C (ICT121)
Dr. Ghada Maher
Lec. 4 Introduction to C Programming 4 March 2024
Outline ‫كلية تكنولوجيا الصناعة والطاقة‬

Difference between an Assembler and a Compiler


Difference between Syntax and Semantics
Difference between Algorithm, Pseudocode , flowchart.
4.1 Assembler, Compiler, and interpreter ‫كلية تكنولوجيا الصناعة والطاقة‬

In general, compiler is a computer program that reads a program written in one language, which is
called the source language, and translates it in to another language, which is called the target language.
Traditionally, source language was a high level language such as C++ and target language was a low
level language such as Assembly language.

However, there are compilers that can convert a source program written in Assembly language and
convert it to machine code or object code. Assemblers are such tools. So, both assemblers and
compilers ultimately produce code that can be directly executed on a machine.

A interpreter is similar to sentence-by-sentence translation, whereas a compiler is similar to translation


to the whole passage.
4.2 Difference between: Assembler and Compiler. ‫كلية تكنولوجيا الصناعة والطاقة‬

Assembler Compiler
It translates the mnemonic codes such as PRN, It translates the high level language to assembly language.
ADD, and SUB etc. To machine language code.
The program, which executes using assembler, It takes time to execute a program, because it first
executes faster, because it directly converts the translates the source code into another compiler’s
source code in machine language. language and then using assembler converts it into
machine language.
‫كلية تكنولوجيا الصناعة والطاقة‬
4.3 Difference between: Compiler and Interpreter
Compiler Interpreter
Compiler translates the entire high level language The Interpreter translates the program written in high
program into the machine language program at once level language into machine language at the time of
before executing it. This optimizes the use of machine executing that program, instructions by instructions.
language instructions in the translated program. That is, it reads the first instruction written in the
Therefore normally compiled programs run faster program and converts that into equivalent machine
than Interpreted programs. The original high level language instructions. Then the CPU watches those
language program is called a s source program. The machine language instructions. After that, the
compiled program i.e. machine language program Interpreter reads and translates the next instruction
generated by the compiler after translation is called and so on.
object program.
Compiler Takes Entire program as input Interpreter Takes Single instruction as input.
Object code is permanently saved for future use. No object code is saved for future use.
Compiler Interpreter
Non time consuming translation method. Time consuming translation method ‫كلية تكنولوجيا الصناعة والطاقة‬

Non time consuming translation method. Time consuming translation method


It requires large space in the computer. Interpreter are easy to write and do not
require large memory space.
Speed of a compiler is very fast. Speed is very slow.
Any change in source program after the Any change in source program during the
compilation requires recompiling of entire translation does not require’s retranslation
code. of entire code.
Intermediate Object Code is Generated. No Intermediate Object Code is Generated.
Conditional Control Statements are Executes Conditional Control Statements are Executes
faster. slower.
Memory Requirement : More (Since Object Memory Requirement is Less.
Code is Generated)
Program need not be compiled every time. Every time higher level program is
converted into lower level program.
Errors are displayed after entire program is Errors are displayed for every instruction
checked. interpreted (if any)
Example : C Compiler. Example : BASIC.
4. 4 Difference between Syntax and Semantics ‫كلية تكنولوجيا الصناعة والطاقة‬

Semantics Syntax
It is the logic or planning of the program. Semantics It is the way of writing the program in a particular
can be written in any of the following ways: programming language. Syntax changes from
1. Flowcharts. language to language.
2. Algorithms.
3. Pseudo codes.
‫‪4.4.1 FLOWCHART‬‬ ‫كلية تكنولوجيا الصناعة والطاقة‬
4.4.2 ALGORITHMS ‫كلية تكنولوجيا الصناعة والطاقة‬

• Once a problem is been properly defined, a detailed, finite, step-by-


step procedure for solving it must be developed. This procedure is
known as algorithm.
• Algorithm can be written in ordinary language, or using formal
procedures that lie somewhere between ordinary and programming
languages.
4.4. 3 PSEUDOCODE ‫كلية تكنولوجيا الصناعة والطاقة‬

Sometimes, it is desirable to translate an algorithm to an intermediate


form, between that of a flowchart and the source code. Pseudocode is
an English approximation of source code that follows the rules, style,
and format of a language but ignores most punctuation’s.
‫كلية تكنولوجيا الصناعة والطاقة‬

Example : Write an Algorithm, Pseudocode ,


and flowchart to add two numbers.
Algorithm to add two numbers.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum
Step 6: Stop
‫كلية تكنولوجيا الصناعة والطاقة‬
Pseudocode to add two numbers

• integer num1, num2, and sum;


• read in num1 and num2;
• add num1 & num2 and set it to sum;
• write sum;
Flowchart to add two numbers. ‫كلية تكنولوجيا الصناعة والطاقة‬
start

Declare variables num1,num2, and sum

Read num1 and num2

sum=num1+num2

Print sum

stop
‫كلية تكنولوجيا الصناعة والطاقة‬
In this week's lab, you’ll Apply
Apply the algorithm, Flowcharts, and Pseudo code to solve a simple problem, then write the code of
this problem using c programming language .
‫كلية تكنولوجيا الصناعة والطاقة‬

‫‪Thank‬‬
‫‪q‬‬
‫‪you‬‬

You might also like