CSE 181 Lecture Notes
CSE 181 Lecture Notes
&
Programming
Reference Books
Introduction to Computers - Peter Norton.
Programming in ANSI C E Balagurusamy.
Numerical Metods Dr. V. N. Vedamurthy & Dr.
N. Ch. S. N. Iyengar.
Computer Fundamentals- Dr. M. Lutfar Rahman
& Dr. M. Alamgir Hossain.
Programming With C Byron Gottfried.
1St Cycle
Introduction to Computers
Computer Basics, Components of Computers, Importance of Computers, types of
computers.
Introduction to Computer Programming
History of C, Importance of C, Sample program: printing message, addition. Basic
structure of C programs. .
Computer Basics
Three basic functions of Computer
Input
Processing
Output
Components of Computer System
Hardware
Software
Humanware
Operational Procedures
SOFTWARE
is a sequence of instructions which directs a computer to
perform certain functions.
generally catagorized as:
1. System Software: consists of programs that help the use of
a computer.
2. Application Software: includes programs to perform user
applictions.
5
Importance&Limitations
Important criteria
Volume of data
Accuracy
Repetitiveness
Complexity
Speed
Common Data
Limitations
cant think.
cant do anything without human instructions.
cant make any adjustment as human being.
Classification
Based on Capacity
o Microcomputers
o Minicomputers
o Mainframe Computers
o Supercomputers
Computer Generations
First Generation (1942-1959)
Utilized vacuum tubes in circuitry and for storage of data
and instructions
Caused tremendous heat problems.
Caused a great number of breakdowns and inefficient
operations.
Programs were written in machine language
combinations of 0 and 1.
Examples: IBM 650, IBM 704, IBM 705, IBM 709, Mark
II, Mark III etc.
Contd..
Second Generation(1960-1965)
Replacement of vacuum tubes by transistors.
Because of high speed operation and small size, perform
a single operation in microseconds and capable of
storing tens of thousands of characters.
Reliable, compact in size and virtually free of heat
problems.
Program written in both machine and symbolic
languages (assembly language).
Examples: IBM 1400, CDC 1604, RCA 501, NCR 300,
GE 200, IBM 1600 etc.
9
Contd..
Third Generation (1965-1971)
Characterized by increased input/output, storage and
processing capabilities.
I/O devices could communicate with computers over
distances via ordinary telephone lines, could display
pictures on television-like screen, make musical sounds
and even accept voice input.
Increased storage capabilities, millions of characters
could be stored and randomly accessed in fractions of a
second, process instructions in nanoseconds.
Example: IBM 360, IBM 370, PDP-8, PDP-11, GE 600
etc.
10
Contd..
Fourth Generation (1972-Present)
Semiconductor storage devices introduced.
Possessed a virtual storage capability in billions and
trillions of characters.
Execute a program many times the size of the machines
actual memory.
Microcomputers using microprocessors as the CPU
proliferated.
Most impressive advancement has occurred in software.
11
Contd..
Fifth Generation
Is yet to come.
Will be capable of reasoning, learning, making
inferences and in ways considered exclusive of humans.
Will be equipped with massive primary-storage
capabilities and extremely fast processing speeds.
Hardware will continue to shrink in size but internal
memory will increase dramatically.
Artificial intelligence will be used extensively to enhance
system behavior.
12
Overview of C
History of C
Most popular computer languages today because it is a
structured, high-level, machine independent language.
Allows software developers to develop programs without
worrying about the hardware platforms where they will
be implemented.
C was evolved from ALGOL, BCPL and B by Dennis
Ritchie at the Bell Laboratories in 1972.
The language became more popular after publication of
the book The C Programming Language by Brian
Kerningham and Dennis Ritchie in 1978.
13
Contd..
To assure that the C language remains standard, in
1983, American National Standards Institute (ANSI)
appointed a technical committee to define a standard for
C.
In December 1989, a version of C is approved known as
ANSI C.
In 1990, it was approved by the International Standards
Organization (ISO).
14
Importance of C
Well suited for writing both system software and
business packages.
Programs written in C are efficient and fast.
C is highly portable.
C language is well suited for structured programming.
Another important feature of C is its ability to extend
itself.
15
Sample Program
Printing a message
#include<stdio.h>
main( )
{
/*printing begins..*/
printf(I see, I remember);
/*..printing ends..*/
}
16
Documentation Section
Link Section
Definition Section
Global Declaration Section
main ( ) Function Section
{
Declaration part
Executable part
}
Subprogram section
Function 1
--Function n
(User-defined functions)
17
C Tokens
In a passage of text, individual words and punctuation
marks called tokens.
Similarly, in a C program the smallest individual units are
known as C tokens.
Six types of tokens in C :
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special Symbols
6. Operators
20
Keywords of C
Flow control (6) if, else, return, switch,
case, default
Loops (5) for, do, while, break, continue
Common types (5) int, float, double, char,
void
structures (3) struct, typedef, union
Counting and sizing things (2) enum, sizeof
Rare but still useful types (7) extern, signed,
unsigned, long, short, static, const
Evil keywords which we avoid (1) goto
Wierdies (3) auto, register, volatile
22
23
Constants
o Numeric constants
1. Integer Constants
2. Real Constants
o Character Constants
1. Single Character Constants
2. String Constants
24
Contd
Integer Constants: An integer constant refers to a
sequence of digits. Three types of integers, namely,
decimal integer, octal integer and hexadecimal integer.
Real Constants: The quantities are represented by
numbers containing fractional parts like 17.548, called
real or floating point constants.
Single Character Constants: contains a single character
enclosed within a pair of single quote marks.
String Constants: sequence of characters enclosed in
double quotes.
25
C Data Types
There are only a few basic data types in
C:
char
int
float
double
Contd..
int, float, char
int (signed/unsigned)(2,4Bytes): used to store
integers.
char (signed/unsigned)(1Byte): used to store
characters
float, double(4,8Bytes): used to store a decimal
number.
27
Declaration of Variables
Primary Type Declaration
data-type v1,v2,vn;
where v1,v2,.vn are the name of variables.
User-Defined Type Declaration
typedef type identifier;
where type refers to an existing data type and identifier
refers to the new name given to data type.
28
NUMBER SYSTEMS
Many Number systems are in use in digital technology.
The most common areDecimal
Binary
Octal and
Hexadecimal.
29
30
31
Invisible characters
Some special characters are not visible
directly in the output stream. These all
begin with an escape character (ie \);
\n
\t
\a
\v
newline
horizontal tab
alert bell
vertical tab
32
33
Categories of C Operators
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Conditional operators
Bitwise operators
Special operators
34
Arithmetic Operators
35
Relational Operators
>
<
>=
<=
==
!=
greater than
less than
greater than or equal to
less than or equal to
equal to
not equal to
36
Logical Operators
37
Assignment Operators
Assignment operators are used to assign the result of an
expression to a variable.
C has a set of shorthand assignment operators of the
form
v op= exp;
is equivalent to
v = v op exp;
where v is a variable, exp is an expression and op is C
binary arithmetic operator.
38
Conditional Operators
A ternary operator pair ? : is available in C to construct
conditional expression of the form
exp1 ? exp2 : exp3
where exp1,
exp1 exp2 and exp3 are expressions.
exp1 is evaluated first. If it is nonzero (true), then the
exp3 is evaluated and becomes the value of the
expression. If exp1 is false, exp3 is evaluated and its
value becomes the value of the expression.
40
Bitwise Operators
C has a distinction of supporting special
operators known as bitwise operators for
manipulation of data at bit level.
Bitwise operators may not be applied to
float or double.
41
Precedence Table
Highest on top
++
-- (Postfix)
++
-- (Prefix)
<<
>>
<
>
&
|
&&
||
42
43