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

Lecture2

Uploaded by

abdallah saad
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)
3 views

Lecture2

Uploaded by

abdallah saad
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/ 21

Introduction to Programming

Lec 2:
Let’s build a simple C program

By:
Abdallah M A Saad
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

2
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

3
Data types

Data is the input to our programs.

C has 5 basic data types;

Character (char),

Integer (int),

Floating point value (float),

Double percission floating point (double),

Void.

You can see that, C basic data types are either text or
numbers.
Data types

Every data type has a range of values to cover;
Data Type Size (Bytes) Range
char 1 A digit, letter or special character
Short int 2 -32,768 → 32,767
unsigned short int 2 0 → 65,535
Int 4 -2,147,483,648 → 2,147,483,647
unsigned int 4 0 → 4,294,967,295
long long int 8 -(2^63) → (2^63)-1
float 4 Up to 6 decimal places
double 8 Up to 15 decimal places
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

6
A simple C program
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

8
Compilation process

Editor Disk

Preprocessor Disk

Compiler Disk

Linker Disk

Loader Disk
Main Memory
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

10
Let’s compile and run the program


To compile the source code;

gcc -o hello.o hello.c


To run the binary file;

./hello.o
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

12
Another C program
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

14
Different prespectives in programming

● User prespective,
● Programmer prespective,

● Machine prespective.
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

16
Arithmetics in C

Arithmetic operator Operation

() Parentheses

Multiplication, division,
*, /, %
modulus

+, - Addition, subtraction
Arithmetics in C


Calculate the results of these equations written in C
style:

7*2/4%2 = ?

5*3+10/3 = ?

8*(2+4/3)-5*2 = ?
Agenda

Data types.

A simple C program.

Compilation process.

Let’s compile and run the program.

Another C program.

Different perspectives in programming.

Arithmetic in C.

Equality and relational operators.

19
Equality and relational operators

Operator Meaning Example in C Meaning of example

== equal X == y Does X equals to y?

!= Not equal X != y Does X not equals to y?

> Greater than X>y Does X greater than y?

< Less than X<y Does X less than y?

Does X greater than or equals


>= Greater than or equal X >= y
to y?
Does X less than or equals to
<= Less than or equal X <= y
y?
Many thanks for
your kind listening

You might also like