You are on page 1of 43

Computer Basics

&
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

Basic Structure of C Programs

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

Some programmer jargon


Some words that will be used a lot:
Source code: The stuff you type into the computer. The
program you are writing.
Compile (build): Taking source code and making a
program that the computer can understand.
Executable: The compiled program that the computer can
run.
Language: (Special sense) The core part of C central to
writing C code.
Library: Added functions for C programming which are
bolted on to do certain tasks.
Header file: Files ending in .h which are included at the
start of source code.
18

Constants, Variables & Data Types


Introduction
Data
Information
Program
Syntax Rules
Character Set
o Letters
o Digits
o Special characters
o White spaces
19

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 & Identifiers


Keywords
All keywords have fixed meanings and these meanings
cannot be changed.
Keywords serve as basic building blocks for program
statements.
Identifiers
Identifiers refer to the names of variables, functions and
arrays.
These are user defined names and consist of a
sequence of letters and digits.
21

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

Rules For Identifiers


First character must be an alphabet (or underscore).
Must consist of only letters, digits or underscore.
Only first 31 characters are significant.
Cannot use a keyword.
Must not contain white space.

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

short, long, signed and unsigned are


additional qualifiers.
26

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

Reading Data from Keyboard


The way of giving values to variables through keyboard
is to use the scanf function. The general format of using
scanf :
scanf(control string, &variable1,&variable2,);
Control string contains the format of data being
received. The ampersand symbol & before each variable
name is an operator that specifies the variable names
address.

30

Defining Symbolic Constants


A constant is defined as follows:
#define symbolic-name value of constant
Examples:
#define PI 3.14159
#define MAX 200
Symbolic names are sometimes called constant identifiers.
#define statement is a preprocessor compiler directive
and is much more powerful than what has been mentioned
here.

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

Operators & Expression


Operators: An operator is a symbol that tells the
computer to perform certain mathematical or logical
manipulations.
Expressions: Operators are used in programs to
manipulate data and variables. They usually form a part
of the mathematical or logical expressions.

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

Five simple binary arithmetic operators


1. + addition or unary plus c = a + b
2. - subtraction or unary minus c = a - b
3. * multiplication c = a * b
4. / division c = a/b
5. % modulo division c = a % b
Here a and b are variables and are known as operands.

Modulo division operator % cannot be used on floating


point data.

35

Relational Operators

Six basic operators for comparison of values in


C. These are typically called relational
operators:
1.
2.
3.
4.
5.
6.

>
<
>=
<=
==
!=

greater than
less than
greater than or equal to
less than or equal to
equal to
not equal to

36

Logical Operators

Logical Operators are used to create


compound expressions
There are two logical operators in C
1. || logical OR
A compound expression formed with || evaluates
to 1 (true) if any one of its components is true
2. && logical AND

A compound expression formed with &&


evaluates to true if all of its components are true

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

Increment & Decrement Operators


Prefix Increment : ++a
example:
int a=5;
b=++a; // value of b=6; a=6;

Postfix Increment: a++


example
int a=5;
b=a++; //value of b=5; a=6;
39

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

You might also like