Lecture2
Lecture2
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
() 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