Introduction To Computer and C Programming Language
Introduction To Computer and C Programming Language
language
Computer?
Computer Programs?
Software?
Hardware?
2
Computer
◦ Device capable of performing computations and
making logical decisions
Computer programs
◦ Sets of instructions that control computer’s
processing of data
Hardware
◦ Various devices comprising computer
Keyboard, screen, mouse, disks, memory, CD-ROM,
processing units, …
Software
◦ Programs that run on computer
3
Six logical units of computer
1. Input unit
“Receiving” section
Obtains information from input devices
Keyboard, mouse, microphone, scanner …
2. Output unit
“Shipping” section
Takes information processed by computer
Places information on output devices
Screen, printer, plotter, projector …
Information used to control other devices
4
Six logical units of computer
5
Six logical units of computer
6
Six logical units of computer
3. Memory unit
Rapid access, relatively low capacity “warehouse”
section
Retains information from input unit
Immediately available for processing
Retains processed information
Until placed on output devices
Memory, primary memory
4. Arithmetic and logic unit (ALU)
“Manufacturing” section
Performs arithmetic calculations and logic decisions
7
Six logical units of computer
5. Central processing unit (CPU)
“Administrative” section
Supervises and coordinates other sections of
computer
6. Secondary storage unit
Long-term, high-capacity “warehouse” section
Storage
Inactive programs or data
Secondary storage devices
Disks
Longer to access than primary memory
Less expensive per unit than primary memory
8
Early computers
◦ Single-user batch processing
Only one job or task at a time
Process data in groups (batches)
Decks of punched cards
Operating systems
◦ Software systems
◦ Manage transitions between jobs
◦ Increased throughput
Amount of work computers process
9
10
11
Multiprogramming
◦ Many jobs or tasks sharing computer’s resources
◦ “Simultaneous” operation of many jobs
Timesharing
◦ Special case of multiprogramming
◦ Users access computer through terminals
Devices with keyboards and screens
Dozens, even hundreds of users
◦ Perform small portion of one user’s job, then moves
on to service next user
◦ Advantage:
User receives almost immediate responses to requests
12
13
14
Personal computers
◦ 1977: Apple Computer
◦ Economical enough for individual
◦ 1981: IBM Personal Computer
◦ “Standalone” units
Computer networks
◦ Over telephone lines
◦ Local area networks (LANs)
Distributed computing
◦ Organization’s computing distributed over
networks
15
16
17
Workstations
◦ Provide enormous capabilities
◦ Information shared across networks
Client/server computing
◦ File servers
Offer common store of programs and data
◦ Client computers
Access file servers across network
UNIX, Linux, Microsoft’s Window-based
systems
18
Three types of computer languages
1. Machine language
Only language computer directly understands
“Natural language” of computer
Defined by hardware design
Machine-dependent
Generally consist of strings of numbers
Ultimately 0s and 1s
Instruct computers to perform elementary operations
One at a time
Cumbersome for humans
Example:
+1300042774
+1400593419
+1200274027
19
Three types of computer languages
2. Assembly language
English-like abbreviations representing elementary
computer operations
Clearer to humans
Incomprehensible to computers
Translator programs (assemblers)
Convert to machine language
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
20
Three types of computer languages
3. High-level languages
Similar to everyday English, use common
mathematical notations
Single statements accomplish substantial tasks
Assembly language requires many instructions to
accomplish simple tasks
Translator programs (compilers)
Convert to machine language
Interpreter programs
Directly execute high-level language programs
Example:
grossPay = basePay + overTimePay
21
History of C
◦ Evolved from two other programming languages
BCPL and B
“Typeless” languages
◦ Dennis Ritchie (Bell Laboratories)
Added data typing, other features
◦ Hardware independent
Portable programs
22
C programs
◦ Built from pieces called functions
C standard library
◦ Rich collections of existing functions
“Building block approach” to creating
programs
◦ “Software reuse”
23
Structured programming (1960s)
◦ Disciplined approach to writing programs
◦ Clear, easy to test and debug, and easy to modify
Pascal
◦ 1971: Niklaus Wirth
Ada
◦ 1970s - early 1980s: US Department of Defense
(DoD)
◦ Multitasking
Programmer can specify many activities to run in
parallel
24
C language
◦ Facilitates structured and disciplined approach to
computer program design
Following several examples
◦ Illustrate many important features of C
◦ Each analyzed one statement at a time
Structured programming
25
C systems
◦ Program-development environment
◦ Language
◦ C Standard Library
26
Program is created in
Editor Disk
Phases of C Programs: the editor and stored
on disk.
Primary
Memory
CPU
CPU takes each
instruction and
executes it, possibly
storing new data
..
.. values as the program
..
executes.
27
Input/output
◦ Scanf()
Standard input stream
Normally keyboard
◦ Printf()
Standard output stream
Normally computer screen
28
Comments
◦ Document programs
◦ Improve program readability
◦ Single-line comment
Begin with //
Preprocessor directives
◦ Processed by preprocessor before compiling
◦ Begin with #
29
Standard output stream object
◦ Printf()
◦ “Connected” to screen
Stream insertion operator
Escape characters
◦ \
◦ Indicates “special” character output
30
Escape Sequence Description
31
Variables
◦ Location in memory where value can be stored
◦ Common data types
int - integer numbers
char - characters
double - floating point numbers
◦ Declare variables with name and data type before use
int integer1;
int integer2;
int sum;
◦ Can declare several variables of same type in one
declaration
Comma-separated list
int integer1, integer2, sum;
32
Variables
◦ Variable names
Valid identifier
Series of characters (letters, digits, underscores)
Cannot begin with digit
Case sensitive
33
Input stream object
◦ (stream extraction operator)
Used with scanf()
Waits for user to input value, then press Enter (Return)
key
Stores value in variable to right of operator
Converts value to variable data type
= (assignment operator)
◦ Assigns value to variable
◦ Binary operator (two operands)
◦ Example:
sum = variable1 + variable2;
34
Variable names
◦ Correspond to actual locations in computer's
memory
◦ Every variable has name, type, size and value
◦ When new value placed into variable, overwrites
previous value
◦ Reading variables from memory nondestructive
35
Scanf(“%d”, integer1); integer1 45
◦ Assume user entered 45
36
A variable is a place-holder for values that
has a name and type.