Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lec 1-2-3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 101

(ICT 1101)

Lecture-1 and 2

Rashed Mazumder

rakhu345@yahoo.com
Contents
• Relationship between hardware and software
components
• The Information Processing Cycle
• Essential Computer Hardware
• Software
• Input/Output Devices
• Computer Program
Computer Hardware Components

Components of a PC
Relationship between hardware
and software
The Information Processing Cycle

It describes the sequence of events in processing


information. It consists of the following contents:
• INPUT
• PROCESSING
• STORAGE
• OUTPUT
The Information Processing
Cycle(continued)
The Information Processing
Cycle(continued)
Input
• Users input data or instruction into the computer system to
be process.
• Input could be either text, graphic, audio or video.
• Input devices are used by users to input data.
• Input devices are any electronic device connected to a
computer and produces input signals.
The Information Processing
Cycle(continued)
Process
Data or instruction being input into the computer system is then
processed by the CPU which controls all activities within the system.
The results of the processed data are then sent to an output device as
usable data.
A CPU interprets and carries out the instructions by processing data
and controlling the rest of the computer’s components.
A CPU consists of two subcomponents; the Control Unit (CU) and the
Arithmetic Logic Unit (ALU).
CU’s main function is to direct the CPU to process data by extracting
instructions from memory and decodes and executes them.
The CU manages a four-step basic operation which is called a machine
cycle. The steps are Fetching, Decoding, Executing & Storing.
The Information Processing
Cycle(continued)
Storage
• Computer storage is important to help users store programs and data to
be used at a later time.
• It is also useful to keep current data while being processed by the
processor until the information is saved in a storage media such as a
hard disk or a diskette.
• Computer storage also stores instructions from a computer program.
• There are two types of computer storage –
i. primary storage
ii. secondary storage.
Storage(continued)
• Primary storage is known as the main memory of a
computer, including RAM (Random-Access Memory)
and ROM (Read-Only Memory). It is an internal
memory (inside the CPU) that can be accessed directly
by the processor.
• Secondary storage an external storage that refers to
various ways a computer can store program and data.
Many complex functions, such as translators for high-
level languages and operating systems are placed in
primary storage. Secondary storage is an alternative
storage. It is very useful to store programs and data for
future use.
The Information Processing
Cycle(continued)
Output
• Output is the result of data processing activity when it
is presented external to the system.
• The output from a computer can be in a form for use
by people, for example, printed or displayed.
• There are four types of output, which are texts,
graphics, audio and video.
Essential Hardware Components
 Input

Processor

Memory

Storage

Output
Essential Hardware
Components(continued)
Input
The devices used to give the computer data or commands are called Input
devices. Includes keyboard, mouse, scanner, etc.
Processor
• A processor is the logic circuitry that responds to and processes the basic
instructions that drive a computer.
• The term processor has generally replaced the term central processing
unit (CPU).
• The processor in a personal computer or embedded in small devices is often
called a microprocessor.
• Short for microprocessor, the central processing unit in a computer.
• The processor is the logic of a computer and functions comparably to a
human central nervous system, directing signals from one component to
another and enabling everything to happen.
Essential Hardware
Components(continued)
Memory
• It is the electronic holding place for instructions and data that your
computer's microprocessor can reach quickly.
• When your computer is in normal operation, its memory usually
contains the main parts of the operating system and some or all of
the application programs and related data that are being used.
• Memory is often used as a shorter synonym for random access
memory (RAM).
• This kind of memory is located on one or more microchips that are
physically close to the microprocessor in your computer.
• Most desktop and notebook computers sold today include at least
16 megabytes of RAM, and are upgradeable to include more.
• The more RAM you have, the less frequently the computer has to
access instructions and data from the more slowly accessed hard
disk form of storage. Memory is also called primary or main
memory.
Essential Hardware
Components(continued)
Storage
• Computer storage is the holding of data in
an electromagnetic form for access by a computer processor.
It is also called secondary storage.
• In secondary storage data resides on hard disks, tapes, and
other external devices.
• Primary storage is much faster to access than secondary
storage because of the proximity of the storage to
the processor or because of the nature of the storage devices.
• On the other hand, secondary storage can hold much more
data than primary storage.
Output

The devices to which the computer writes data are


called Output devices. Often converts the data into a human
readable form. Monitor and printer are output devices.
Software
• Computer cannot do anything on its own.
• It is the user who instructs computer; what to do,
how to do and when to do.
• In order to perform any task, you have to give a set
of instructions in a particular sequence to the
computer.
• These sets of instructions are called Programs.
• Software refers to a set of programs that makes the
hardware perform a particular set of tasks in
particular order.
Software(continued)
Software can be classified mainly into
following categories:

i. System software
ii. Application software
Software(continued)

System software
When you switch on the computer the programs stored
in ROM are executed which activates different units of
your computer and makes it ready for you to work on
it. This set of programs can be called system software.
It can be categorized into two parts:
 Operating system
 Utilities
System software
(Operating system)
• An operating system is a system software that provides
an interface for a user to communicate with the
computer, manages hardware devices (disk drives,
keyboard, monitor, etc), manages and maintains disk
file systems and supports application programs.
• Some popular Operating systems are UNIX, Windows
and Linux.
System software(Utilities)
• Although operating system provides all the features,
users need to use and maintain their systems,
inevitably, they still do not meet everyone’s
expectations.
• This has led to another type of system software called
"Utilities".
• These are programs that bridge the gap between the
functionality of an OS and the needs of users.
• Utility programs are a broad category of software
such as compress (zip)/uncompress (unzip) files
software, anti virus software, split and join files
software, etc.
Application software
Application software is a set of programs, which are
written to perform specific tasks.
For example: An application package for managing
library known as library information system is used
to manage information of library such as: keeping
book details, account holder details, book issue
details, book return details etc.
Application software can be broadly classified into
two types:
i. Generalized packages
ii. Customized packages
Application software(Generalized
Packages)
• These are user friendly software written to cater to user’s very general
needs such as preparing documents, drawing pictures, database to
manage data/information, preparing presentations, play games etc.
• It is a group of programs that provide general purpose tools to solve
specific problems.
• Some of the generalized packages are listed below:
Word Processing Software(for preparing documents): Word Perfect,
MS-Word, OpenOffice.org Writer l
 Spreadsheets (Data Analysis): Lotus Smart suites, MSExcel,
OpenOffice.org Calc, Apple Numbers l
Presentations : Presentation Graphics, MS-PowerPoint,
OpenOffice.org Impress l
Database Management System: MS-Access, OpenOffice.org Base,
MS-SQL Server, ORACLE l
Graphics Tools: Paint shop pro, Adobe Photoshop
Application software(Customized
Packages)

• These are the applications that are customized (or


developed) to meet the specific requirements of an
organization/institution.
• For Example: Student information details, Payroll
packages, inventory control etc.
• These packages are developed using high-level
computer language.
Input/Output devices
Input Devices are given below:
• Keyboard
• Mouse
• Light Pen
• Optical/magnetic Scanner
• Touch Screen
• Microphone for voice as input
• Track Ball
Input/Output devices(continued)

Output Devices are given below:

• Monitor (Visual Display Unit)

• Printers

• Plotter

• Speakers
Input Device(Keyboard)
• A keyboard is the most common input device.
• Several kinds of keyboards are available, but they
resemble each other with minor variations.
• The keyboard in most common use is the QWERTY board.
• Generally standard keyboard has 104 keys.
• In these keyboards, the cursor control keys are duplicated
to allow easier use of the numeric pad.
Input Device(Mouse)
• A mouse is an electro-mechanical, hand-held device.
• It is used as a pointer.
• It can perform functions like selecting menu commands, moving icons,
resizing windows, starting programs, and choosing options.
• The most common mouse uses an internal, magnetically coated ball, to
detect the movement of the mouse across a flat surface, usually a
desktop.
• Now a days Optical or laser mouse is used to detect the movement. All
windows based applications today are designed to work with a mouse.
• However, it cannot substitute all keyboard operations.
• It can be alternative for commands based operations.
Input Device(Light pen)
• An input device that utilizes a light-sensitive detector
to select objects on a display screen.
• A light pen is similar to a mouse, except that with a
light pen you can move the pointer and select objects
on the display screen by directly pointing to the
objects with the pen.
Input Device(Optical scanner)
• These devices are used for automatic data
collection.
• The devices of this category completely
eliminate manual input of data.
• For example, the bar-code reader is actually
just a special type of image scanner.
• An image scanner translates printed images
into an electronic format that can be stored in a
computer’s memory, and with the right kind of
software, one can alter a stored image.
• Another example of scanner is optical
character recognition (OCR) device, used by
banks to convert the scanned image of a typed
or printed page into text that can be edited on
the computer.
Input Device(Touch Screen)
• Touch panel displays and pads are
now being offered as alternatives
to keyboard.
• Here the input can be given
through the computer screen, that
accepts the input through monitor;
users touch electronic buttons
displayed on the screen or they
may use light pen.
Input Device(Microphone)
• Microphone is an input device,
which takes voice as input.
• The voice communication is more
error-prone than information Desktop
through keyboard. microphone

• There are two types of


microphones available :
1. Desktop Microphone
Handheld
2. Hand held Microphone microphone
Input Device(Trackball)
• Trackball, a pointing device, is a mouse
lying on its back.
• To move the pointer, you rotate the ball
with your thumb, your fingers, or the palm
of your hand.
• There are usually one to three buttons next
to the ball, which you use just like mouse
buttons.
• The advantage of trackballs over mouse is
that the trackball is stationary so it does not
require much space to use it. In addition,
you can place a trackball on any type of
surface, including your lap.
• For both these reasons, trackballs are
popular pointing devices for portable
computers.
Output Device(Monitor)
• A "computer screen" or "display."
• The monitor displays the computer's user interface and open
programs, allowing the user to interact with the computer,
typically using the keyboard and mouse.
• It is made up of circuitry, a screen, a power supply, buttons to
adjust screen settings, and casing that holds all of these
components.
• The first computer monitor was part of the Xerox Alto
computer system, which was released on March 1, 1973.
• There are three types of monitors, namely- CRT, LCD & LED.
Output Device(Monitor)-CRT
monitor
• CRT stands for Cathode Ray Tube.
• An analog computer display or television set with a
large, deep casing. This type of monitor uses streams
of electrons that activate dots or pixels on the screen to
create a full image.
How CRT monitor works?
• Inside a CRT monitor is a picture tube that
narrows at the rear into a bottleneck.
• In the bottleneck area is a charged filament
or "cathode" enclosed in a vacuum tube.
• When electricity is supplied to this, the
filament heats up and a stream or "ray" of
electrons pours off of it.
• The negatively charged electrons are
attracted to positively charged "anodes"
which focus the particles into three narrow
beams, accelerating them to strike a
phosphor-coated display screen.
How CRT monitor works?(continued)
• The beam of electrons passes through a
perforated mask that allows the appropriate
phosphors (that create color) to be struck 20-
30% while absorbing the rest as heat. The
perforated mask became known as the
shadow mask.
• Phosphor glows when exposed to radiation,
absorbing ultraviolet light and emitting
visible, colored light.
• Materials that emit red, green and blue light
are used in a color monitor, arranged as
"stripes" made up of dots of color.
• The three beams are used to excite the three
colors in combinations needed to create the
various hues that form the picture.
Output device(Monitor)-LCD monitor
• LCD stands for Liquid Crystal Display.
• Liquid crystal was discovered by an Austrian botanist Fredreich
Rheinizer in 1888.
• "Liquid crystal" is neither solid nor liquid (an example is soapy water).
• It uses LCD technology to show clear images, and is found mostly in
laptop computers and flat panel monitors.
• This technology has replaced the traditional cathode ray tube (CRT)
monitors, which were the previous standard and once were considered
to have better picture quality than early LCD variants.
• With the introduction of better LCD technology and its continuous
improvement, LCD is now the clear leader over CRT, in terms of color
and picture quality, not to mention capabilities for large resolutions.
• In 1997, however, several manufacturers began offering full-size LCD
monitors as alternatives to CRT monitors.
How LCD monitor works?

Cold
Cathode
Fluorescent The light goes through layers of glass, polarizers, The colors and light combine
thin film transistors (TFT), liquid crystals, and to produce the images you
(CCFL) see on your display.
backlighting color filters.
is required.
How LCD monitor works?(continued)
• The source of light produces a light. The light passes
through liquid crystal, its intensity is influenced by
other layers, especially by liquid crystal.
• The signal comes in from the video controller which is
decoded and understood by a display controller on the
monitor itself. The controller has two things to control -
the electrics of the pixels and the light source.
• Then it passes through the polarizing filters placed at
the two ends of TFT(Thin Film Transistor).
How LCD monitor works?(continued)
• The two filters are exact opposites of each other.
• As the light from the light source behind the first filter comes in, the
filter effectively whites it out - which means that if it was to pass
through the liquid crystals with no interaction, the filter on the other
side would polarize it back to black, leaving no color being emitted.
• In fact, alternate current - leaving the crystals 'dead in the water' - is
how black is created on a panel.
• However, if the electrodes apply current to the liquid crystals they
twist and change the way that the light is passed through, altering its
polarization and this then results in the correct color coming out of the
second polarizing filter and being displayed to the user.
• The actual image on a TFT is made up of a matrix of pixels and has a
sandwich-like structure. Unlike with CRTs, there's no complex
equation of dot pitch and image area to try and calculate - the native
resolution of the monitor is simply the number of pixels contained in
the matrix.
How LCD monitor works?(continued)
• If it's a 17" monitor, chances are there are 1280 pixels in
the matrix horizontally, and 1024 vertically.
• Each pixel is made up of three sub-pixels, which have
red, green and blue filters in front of them, just as each
pixel on a CRT has RGB phosphors. The sub pixels are
made up of a group of liquid crystal molecules. These
molecules are suspended between transparent electrodes
and are mashed between two polarizing filters.
Output device(Monitor)-LED monitor

• Stands for "Light-Emitting Diode."


• It are the latest types of monitors in the market today.
• Like LCD, it is again a flat panel display making use
of light-emitting diodes for back-lightning instead of
Cold Cathode Fluorescent (CCFL) back-lightning
used in LCDs.
• Primarily, the display is of LCD only but the back-
lightning is done by LEDs.
Output device(Printer)

• After a document is created on the computer, it can


be sent to a printer for a hard copy (printout).
• Some printers offer special features such as colored
and large page formats.
• Some of the most commonly used printers are:
1. Laser Printer
2. Ink Jet Printer
3. Dot Matrix Printer
4. Line Printer
Output device(Printer)-Laser Printer

• A laser printer produces high quality print that one


normally finds in publishing.
• It is extremely fast and quiet. Moreover, the operation of
a laser printer is easy with automatic paper loading and
no smudging or messing up of ink ribbons.
• The fastest laser printer can print up to 200 pages per
minute in monochrome (black and white) and up to 100
pages per minute in color.
Output device(Printer)-InkJet Printer
• An ink-jet printer creates an image directly on paper by
spraying ink through as many as 64 tiny nozzles.
• Although the image it produces is not generally quite as
sharp as the output of a laser printer, the quality of ink-jet
images is still high.
• In general, ink-jet printer offers an excellent middle
ground between dot matrix and laser printer.
• Like laser printer, an ink-jet printer is quiet and
convenient, but not particularly fast.
• Typically, an ink-jet printer is more expensive than a dot-
matrix printer, but costs only half as much as a laser
printer.
Output device(Printer)-Dot Matrix Printer
• The dot matrix printer was very popular at one point of
time. It is a very versatile and inexpensive output
device.
• In dot matrix printer the print head physically "hits" the
paper through the ribbon and produces text (or images)
by combinations of dots; hence the name dot matrix
printer.
• Its speed is measured in characters per second (CPS).
• Although it is less expensive, it is louder, slower and
produces lower print quality.
Output device(Printer)-Line Printer
• A line printer is generally used with large computer
systems to produce text based data processing
reports.
• Line printers are high-speed printers with speeds
ranging anywhere from 100 to about 3800 lines per
minute. In the past, print quality on line printers was
not high.
• Developments in technology are improving the print
quality on line printers.
Output device(Plotter)
• A plotter is a special kind of output device that, like a printer, produces images
on paper, but does so in a different way.
• Plotters are designed to produce large drawings or images, such as construction
plans for buildings or blueprints for mechanical objects.
• A plotter can be connected to the port normally used by a printer. An array of
different colored pens in a clip rack and a robotic arm is part of plotter.
• The instructions that a plotter receives from a computer consist of a color, and
beginning and ending coordinates for a line.
• With that information, the plotter picks up the appropriate pen through its arm,
positions it at the beginning coordinates drops the pen down to the surface of
the paper and draws to the ending coordinates.
• Plotters draw curves by creating a sequence of very short straight lines.
• Plotters usually come in two designs:
1. Flat Bed: Plotters of small size to be kept on table with restriction of paper
size.
2. Drum: These plotters are of big size using rolls of paper of unlimited length.
Output device(Plotter)- image
Output device(Speaker)
Speakers are another type of output device, which allow
you to listen to voice like music, and conversation with
people.
What is a program?
A program is a list of instructions for the
computer to perform a specific action or a
specific task such as:
'Calculate the sum of the numbers from 1 to
10‘
'Print “I like programming”‘
'Output the current time'
Important Notations
1 Byte = 8 bit
1 Word = 2 Byte
1024 Byte = 1KB
1024 KB = 1MB
Reference Books
1. Herbert Schildt, “Teach yourself”.
2. Schaum’s ouline, “Programming in C”.
3. Jahangir Mawla, “Programming in C”.
4.Yamath Kanathkar, “Let us C”.
5. Yamath Kanathkar, “Pointer in C”.
6. E. Balagurusamy, “ Programming in ANSI C”.
Programming Language

A programming language is an artificial language


designed to communicate instructions to a machine,
particularly a computer. Programming languages can
be used to create programs that control the behavior
of a machine and/or to express algorithms.
Example: Fortran, Pascal, C, C++, Java etc.
More tactically . . . . .
•Programming is instructing a computer to do
something for you
•But computer can only understand 0 and 1!
- It doesn't understand our language
- How can we tell computer what to do and
how?
•We can do this with the help of a
programming language
LEVELS OF PROGRAMMING LANGUAGE

• First Generation programming Language or Machine


Level Language
• Second Generation Programming Language or Assembly
Level Language
• Third Generation Programming Language or High Level
Language
• Fourth Generation Programming Language or Very High
Level Language
• Fifth Generation Programming Language or Visual
Programming Language
• Open Programming Language
LEVELS OF PROGRAMMING LANGUAGE
First Generation programming Language or Machine Level
Language
Originally, no translator was used to compile or assemble the
first-generation language.
The first-generation programming instructions were entered
through the front panel switches of the computer system.
This is very expensive. There was originally no compiler or
assembler to process the instructions in 1GL.
The instructions in 1GL are made of binary numbers,
represented by 1s and 0s.
This makes the language suitable for the understanding of the
machine but far more difficult to interpret and learn by the
human programmer.
LEVELS OF PROGRAMMING LANGUAGE

First Generation Programming Language or


Machine Level Language
LEVELS OF PROGRAMMING LANGUAGE
Second Generation programming Language or Assembly Level
Language
 It is a grouping of programming languages associated with
assembly languages.
Unlike the first generation languages, programs can be written
symbolically, using English words (also known as mnemonics), in
a way that a human can understand and are subsequently
converted into machine language by an assembler.
The code can be read and written by a programmer.
The language is specific to a particular processor family and
environment.
2GL are mostly used for the implementation of low-level kernels
and drivers and for performance-oriented and processing-intensive
applications such as computer games, graphic manipulation
applications and video editing applications.
Assembly Language
•Enables machine code to be represented in
words and numbers.
•Example of a program in assembler language:
MOV A, 010
ADD A, 101
•Easier to understand and memorize (called
Mnemonics), compared to machine code but
still quite difficult to use.
•Processor and Architecture dependent
LEVELS OF PROGRAMMING LANGUAGE
Second Generation programming Language or
Assembly Level Language
LEVELS OF PROGRAMMING LANGUAGE
Third Generation programming Language or High Level
Language
 It is a programming language that is machine-independent,
meaning programs written in that language can be compiled to
run on many different devices.
3GLs feature more abstraction than previous generations of
languages, and thus can be considered higher level languages
than their first and second generation counterparts.
3GLs first appeared in the 1950s with the development
of FORTRAN, ALGOL, and COBOL. These languages are
considered "high-level," even though they are a much lower-
level than modern high-level programming languages such as
C, C++, C#, Java, Ruby, JavaScript, etc.
LEVELS OF PROGRAMMING LANGUAGE

Fourth Generation programming Language or Very High


Level Language
It is a computer programming language envisioned as a
refinement of the style of languages classified as third-
generation programming language (3GL).
Each of the programming language generations aims to provide
a higher level of abstraction of the internal computer
hardware details, making the language more programmer-
friendly, powerful and versatile.
While the definition of 3GL has changed over time, it can be
typified by operating more with large collections of information
at once rather than focusing on just bits and bytes.
LEVELS OF PROGRAMMING LANGUAGE

Fourth Generation programming Language or Very


High Level Language(continued)
Languages claimed to be 4GL may include support
for database management, report
generation, mathematical optimization, GUI
development, or web development.
The concept of 4GL was developed from the 1970s
through the 1990s, overlapping most of the development
of 3GL.
 Ex: SQL, NOMAD and FOCUS.
LEVELS OF PROGRAMMING LANGUAGE
Fifth Generation programming Language or Visual
Programming Language
It is designed to make the computer solve a given problem
without the programmer.
This way, the user only needs to worry about what problems
need to be solved and what conditions need to be met, without
worrying about how to implement a routine or algorithm to
solve them.
Fifth-generation languages are used mainly in artificial
intelligence research.
Prolog, OPS5 and Mercury are examples of fifth-generation
languages.
LEVELS OF PROGRAMMING LANGUAGE

Open Programming Language


• Ex: Symbian OS, Android, IOS etc.
LEVELS OF PROGRAMMING LANGUAGE
What is C?

• C is general purpose computer programming


language. This language was developed at the
Bell Laboratories in 1960-1973 by
Dennis Ritchie.
• The main goal for creating the C language was the
ability to implement system software.
• The C language is the language that had very huge
influence on many other programming languages.
So this is the reason, why C is so popular.
Why it is called C?
• The C language is called so because of a very simple reason. It
was named after the language, that was called B. The very first
Unix systems were written in low level assembler language.
These systems were built for working with PDP-7, the
minicomputer, that was introduced in 1965. Ken Thompson
developed a compiler for high level language, that was called
B.
• Dennis Ritchie started working with it. He worked with B
language to create a new language. He called this high level
language as C. This name is very concise and easy to
remember. But the reason why C become so popular is it's
functionality and very well developed structure.
Why to use C?
C is a structured programming language language.. It is
considered a high
high--level language because it allows the
programmer to concentrate on the problem at hand and
not worry about the machine that the program will be
using.. While many languages claim to be machine
using
independent, C is one of the closest to achieving that
goal.. That is another reason why it is used by software
goal
developers whose applications have to run on many
different hardware platforms
platforms..
History of C
1960 ALGOL (Algorithmic Language) International group

1967 BCPL (Basic Combined Martin Richards


Programming Language)

1970 B Ken Thompson

1972 Traditional C Dennis Ritchie

1978 K&R C Kernighan & Ritchie

1989 ANSI C ANSI Committee

1990 ANSI/ISO C ISO Committee

1999 C99 Standardization Committee


Importance of C
• It is a robust language
• It has the capabilities of an assembly language with
the features of a high level language. So it is well
suited for writing both system software and business
packages.
• ANSI C has only 32 keywords.
• C is highly portable
• C is well suited for structured programming
• C has the ability to extend itself.
Components of C

• main() function
• Library functions
• Header files
Components of C (main ()function)
• Although a C program may contain several functions, the
only function that C must have is the main().
• The main() function is where execution of your program
begins.
• That is, when your program begins running, it starts
executing the statements inside main(), beginning with the
first statement after the opening curly brace.
• The program ends when main()’s closing curly brace is
reached.
• Although the curly brace doesn’t actually exist in the
compiled version of the program, but it is helpful to
understand.
Components of C (library functions)
• Library functions in C language are inbuilt functions which are grouped
together and placed in a common place called library.
• Each library function in C performs specific operation.
• We can make use of these library functions to get the pre-defined output
instead of writing our own code to get those outputs.
• These library functions are created by the persons who designed and
created C compilers.
• The advantage of adding user defined function in C library is, this
function will be available for all C programs once added to the C library.
• Example:
printf(): to show the output;
scanf(): to take the input;
getchar(): returns the next character typed on the keyboard;
putchar(): outputs a single character to the screen, etc.
Components of C (header files)
• Another component common to most C programs is the
header file.
• In C, information about the standard library functions is
found in various files supplied with the compiler.
• These files all end with a .h extension.
• The C compiler uses the information in these files to handle
the library functions properly.
• These files are added in the program using the #include
preprocessor directive.
• When we include header files in our C program using
“#include<filename.h>” command, all C code of the header
files are included in C program. Then, this C program is
compiled by compiler and executed.
Components of C (header files) continued
• All C compilers use their first phase of compilation a preprocessor,
which performs various manipulations on the source file before it is
compiled.
• Preprocessor directives are not actually part of the C language, but
rather instructions from you to the compiler.
• The #include directive tells the preprocessor to read in another file
and include it in your program. Later of this slide we will learn it.
• The most common header file is called stdio.h which means
standard input output.
• #include<stdio.h>
• It doesn’t end with semicolon. Because #include is not a C keyword
that can define a statement. Instead, it is an instruction to the C
compiler itself.
C Program (Example-1)
uses standard library
input and output functions
#include <stdio.h>
(printf)
the program int main (void)
{
begin of program printf (“Bangladesh\n");
statements return 0;
}
end of program

main: a special name that indicates where the program must begin execution. It is a special
function.
first statement: calls a routine named printf, with argument the string of characters “Programming is
fun \n”
last statement: finishes execution of main and returns to the system a status value of 0
(conventional value for OK)
C Program (Example-2)

#include <stdio.h>
#include <stdlib.h>
int main()
{
printf(“Thank You!\n");
return 0;
}
C Program (Example-2)

#include <stdio.h>
#include <stdlib.h> standard Library, input-output, header-file

int main()
{
printf(“Thank You!\n");
return 0;
}
C Program (Example-2)

#include <stdio.h>
#include <stdlib.h>
Beginning of program
int main()
{
printf(“Thank You!\n");
return 0;
}
C Program (Example-2)

#include <stdio.h>
#include <stdlib.h>
int main()
{ Start of Segment
printf(“Thank You!\n");
return 0;
End of Segment
}
C Program (Example-2)

#include <stdio.h>
#include <stdlib.h>
int main()
{ Function for printing text

printf(“Thank You!\n"); End of statement


return 0;
}
Output of the previous
program

Thank you!
Compiling and running C programs
Traditional command-line compiler has the following
steps to create and compile a program:

• Create the program using an editor

• Compile the program

• Execute the program.


Compiling and running C
programs(continued)
• The file that contains the C program that you create is
called the source file.
• The file that contains the compiled form of your
program that the computer executes is called the
object file.
• Once the program is run a file named executable file is
created.
Compiling and running C programs
(continued)

Editor
Source code
file.c

Compiler
Object code
file.obj

Libraries Linker
Executable code
IDE (Integrated
file.exe
Development
Environment)
Compilers/Interpreters
Source Machine
Compiler Code Source
Code
Code
Interpreter
Input Output
Input Executable Output
data data
data Program data

Compiler: analyzes program and Interpreter: analyzes and executes


translates it into machine program statements at the same
language time
Executable program: can be run Execution is slower
independently from compiler as Easier to debug program
many times => fast execution
List of some header files with their
respective library functions’ uses
1. stdio.h: I/O functions:
1. getchar() returns the next character typed on the
keyboard.
2. putchar() outputs a single character to the screen.
3. printf() as previously described
4. scanf() as previously described

2. string.h: String functions


1. strcat() concatenates a copy of str2 to str1
2. strcmp() compares two strings
3. strcpy() copys contents of str2 to str1
List of some header files with their
respective library functions’ uses
#include<stdio.h>
int main(){
char c;
printf("Enter character: ");
c = getchar();
printf("Character entered: ");
putchar(c);

return 0;
}
List of some header files with their respective library
functions’ uses(continued)
3.ctype.h: Character functions
1. isdigit() returns non-0 if arg is digit 0 to 9
2. isalpha() returns non-0 if arg is a letter of the alphabet
3. isalnum() returns non-0 if arg is a letter or digit
4. islower() returns non-0 if arg is lowercase letter
5. isupper() returns non-0 if arg is uppercase letter

4. conio.h: I/O functions:


1. clrscr(): This function is used to clear the output screen..
2. getch(): It reads character from keyboard.
3. getche(): It reads character from keyboard and echoes to o/p screen
4. textcolor(): This function is used to change the text color
5. textbackground(): This function is used to change text background
List of some header files with their respective library
functions’ uses (continued)

5.math.h: Mathematics functions


1. acos() returns arc cosine of arg
2. asin() returns arc sine of arg
3. atan() returns arc tangent of arg
4. cos() returns cosine of arg
5. exp() returns natural logarithim e
6. fabs() returns absolute value of num
7. sqrt() returns square root of num
List of some header files with their respective
library functions’ uses(continued)

6. time.h: Time and Date functions


1. time() returns current calender time of system
2. difftime() returns difference in secs between two times
3. clock() returns number of system clock cycles since
program execution
7. stdlib.h:Miscellaneous functions
1. malloc() provides dynamic memory allocation, covered
in future sections
2. rand() as already described previously
3. srand() used to set the starting point for rand()
Usefulness of Comment-Line

• /*………………*/ (This is multi-line Comment)


Ex: /* printf(“HelloWorld”);
scanf(“%d”,&a);*/
• //………………….. (This is single-line Comment)
Ex: //printf(“HelloWorld”);
//scanf(“%d”,&a);
Preprocessor Directive
• Its is an unique Feature in C
• A program can use the tools provided by preprocessor
to make his program easy, modify, portable and more
efficient.
• Line that begins with ‘#’ is called as preprocessor.
• It can be divided into three categories.
- Macro substitution
- File inclusion
- Compiler control division
Preprocessor Directive(continued)
Preprocessor Directive(Continued)
How to develop a program
• Analyze the program.
• Identify various processing steps needed to solve the problem and
represent them in a particular way(algorithm, pseudo code, flow chart,
etc.).
• Refine step 2 in a way that all the processing steps are detailed enough
such that every processing steps is equivalent to one instruction of the
programming language.
• Add the syntax of the programming language to the above representation
and it becomes the program.
• Type the program and compile it after removing all syntax related errors.
• Run the program and check it with different types of input to verify its
correctness. If the results are incorrect for any combination of inputs,
review all the processing steps and identify the mistake. Correct the
mistake and again continue with step number 4 above.
Conclusion

Let’s have a great journey with C


Thank You

You might also like