Lecture 1 - Introduction
Lecture 1 - Introduction
PROGRAMMING IN C
Masoud H. Mahundi
[email protected]
+255 713832252
Assessment
Assignments – during lectures and special assignments – 15
• Hardware
– Various devices comprising a computer
– Keyboard, screen, mouse, disks, memory, CD-ROM, and
processing units
• Software
– Programs that run on a computer
Software Categories
• System SW
– Programs written for computer systems
• Compilers, operating systems, …
• Application SW
– Programs written for computer users
• Word-processors, spreadsheets, & other application packages
• Stock management
• Calculators
English-like statements to a
language understandable by
machines Machine
readable
We “run” the machine readable
– the executable
PL hierarchy
We program for different machines
computers
Mobile phones
cars
robots
Evolution of Programming languages
– First Generation : Machine languages
– Strings of numbers giving machine specific instructions
– Example:
+1300042774
+1400593419
+1200274027
– Second Generation : Assembly languages
– English-like abbreviations representing elementary computer
operations (translated via assemblers)
– Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
– Third Generation : High-level languages
• Codes similar to everyday English
• Use mathematical notations (translated via compilers)
• Example: grossPay = basePay + overTimePay
What does the computer understand?
• Computer only understands machine language
instructions.
Why C Programming
Strengthen the knowledge on structured programming
- Bell Labs.
Dennis Mac Alistair Ritchie (1941 – 2011) and Brian Kernighan
operating system
There came a need for abstraction and portability into the resulting UNIX.
Denis and Brian set to develop a language that would develop the UNIX.
C was developed and used
Operating System.
Dennis MacAlistair Ritchie
(September 9, 1941 – c. October 12, 2011)
~~ Denis Ritchie ~~
Up until 1978, C was being used only within the Bell Labs for UNIX development
It was in 1978 when Ritchie and Kernighan published the formal description of the
language
The language came to be known as K & R C – The language was made public to the
world
In 1983 the ANSI started the process of standardising the language which went to 1989
In 1990 the ISO started the same process
The language was therefore open to the public
History of C Language
TIME STAGE OF DEVELOPMENT
The above program is meant to print to the screen the words “Hello
World”
Line 1: #include <stdio.h>
A pre-processor directive
It tells the compiler to include the content of a file named stdio.h
A programmer does not write everything for themselves
They often use files coming with the compilers’ library
Richness of a language is also measured in how big is the library
2. What is programming?
5. What is “compilation”?
7. What is “portability”?
9. What is a “comment”?
Data Types
Data Types
Programs are always meant to be
processing some input data and generate some output data
There are basically three types of floating point numbers, float, double
and long double
Normally float means 4 bytes of memory, double means 8 bytes while
long double means 10 bytes.
Wake Up
Masoud H. Mahundi
Variables
Some external data entered by
Users, other systems, external files or a result of some computations
name “salary”
This memory is reserved in what is referred to as a “stack”
Examples of declaration
1. float salary;
2. int age;
3. double weight;
4. char sex;
5. char username[15];
1. #include<stdio.h>
2. main(){
3. int intv1;
float salary = 4500.52;
4. float flov1 = 13.523;
int agSalary;
5. intv1 = (int)flov1;
agSalary = (int) salary;
6. printf("%d",intv1);
7. printf("\n");
8. }
Constants
Unlike variables, constants remain unchanged throughout the program
Often not values entered by the users
AS A PREPROCESSOR DIRECTIVE
1. #include<stdio.h>
2. float PI 3.142
3. main(){
4. float radius, area;
5. printf(“Enter Radius: “);
6. scanf(“%f”, &radius);
7. printf(“The Area is %0.2f”, PI*radius*radius);
8. }
Constants
Unlike variables, constants remain unchanged throughout the program
Often not values entered by the users
2. int age,
3. double weight
4. character sex;
5. char username[15];
8. float #pesa;
9. int xxx;