CProgramming_unit1ver1.1
CProgramming_unit1ver1.1
Module 1
Fig: Keyboard
Types of Keys
Numeric Keys: It is used to enter numeric data or move the cursor. It usually
consists of a set of 17 keys.
Typing Keys: The letter keys (A-Z) and number keys (09) are among these keys.
Control Keys: These keys control the pointer and the screen. There are four
directional arrow keys on it. Home, End, Insert, Alternate (Alt), Delete, Control (Ctrl),
etc., and Escape are all control keys (Esc).
Special Keys: Enter, Shift, Caps Lock, Num Lock, Tab, etc., and Print Screen are
among the special function keys on the keyboard.
Function Keys: The 12 keys from F1 to F12 are on the topmost row of the keyboard.
i. Mouse
The most common pointing device is the mouse. The mouse is used to move a little
cursor across the screen while clicking and dragging.
Fig: Mouse
ii. Joystick
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
A joystick is a pointing device that is used to move the cursor on a computer screen. A
spherical ball is attached to both the bottom and top ends of the stick.
Fig: Joystick
The joystick’s function is comparable to that of a mouse. It is primarily used in CAD
(Computer-Aided Design) and playing video games on the computer.
iii. Track Ball
Track Ball is an accessory for notebooks and laptops, which works on behalf of a mouse. It
has a similar structure to a mouse. Its structure is like a half-inserted ball and we use
fingers for cursor movement.
Fig: Scanner
vi. Optical Mark Reader (OMR)
An Optical Mark Reader is a device that is generally used in educational institutions to
check the answers to objective exams. It recognizes the marks present by pencil and pen.
vii. Optical Character Reader (OCR)
OCR stands for optical character recognition, and it is a device that reads printed text.
OCR optically scans the text, character by character turns it into a machine-readable code,
and saves it to the system memory.
viii. Magnetic Ink Card Reader (MICR)
It is a device that is generally used in banks to deal with the cheques given to the bank by
the customer. It helps in reading the magnetic ink present in the code number and
cheque number.
ix. Bar Code Reader
A bar code reader is a device that reads data that is bar-coded (data that is represented
by light and dark lines).Bar-coded data is commonly used to mark things, number books,
and so on.
x. Web Camera
Because a web camera records a video image of the scene in front of it, a webcam is an
input device. Webcam is a computer-connected tiny digital video camera.
xi. Microphone
The microphone works as an input device that receives input voice signals and also has
the responsibility of converting it also to digital form. It is a very common device that is
present in every device which is related to music.
b. Output Devices
Output Devices are the devices that show us the result after giving the input to a computer
system. Output can be of many different forms like image, graphic audio, video, etc. Some
of the output devices are described below.
i. Monitor
Monitors, also known as Visual Display Units (VDUs), are a computer’s primary output
device. It creates images by arranging small dots, known as pixels, in a rectangular
pattern. The amount of pixels determines the image’s sharpness.
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
The two kinds of viewing screens used for monitors are described below.
Cathode-Ray Tube (CRT) Monitor: Pixels are minuscule visual elements that make
up a CRT display. The higher the image quality or resolution, the smaller the pixels.
Flat-Panel Display Monitor: In comparison to the CRT, a flat-panel display is a type
of video display with less volume, weight, and power consumption. Flat-panel displays
are currently used in calculators, video games, monitors, laptop computers, and
graphical displays.
Fig: Monitor
ii. Printer
Printers are output devices that allow you to print information on paper. There are
certain types of printers which are described below.
Impact Printers
Character Printers
Line Printers
Non-Impact Printers
Laser Printers
Inkjet Printers
Impact Printer
Characters are printed on the ribbon, which is subsequently crushed against the
paper, in impact printers. The following are the characteristics of impact printers:
Exceptionally low consumable cost.
Quite noisy
Because of its low cost, it is ideal for large-scale printing.
Character Printers
Character Printer has the capability to print only one character at a time. It is of two
types.
Dot Matrix Printer
Daisy Wheel
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
Line Printers
Line Printers are printers that have the capability to print one line at a time. It is of
two types.
Drum Printer
Chain Printer
Non-Impact Printers
Characters are printed without the need for a ribbon in non-impact printers.
Because these printers print a full page at a time, they’re also known as Page
Printers. The following are the characteristics of non-impact printers:
Faster
They don’t make a lot of noise.
Excellent quality
Supports a variety of typefaces and character sizes
Laser Printers
Laser Printers use laser lights for producing dots which will produce characters on
the page.
Inkjet Printers
Inkjet printers are printers that use spray technology for printing papers. High-
quality papers are produced in an Inkjet printer. They also do color printing.
iii. Speakers
Speakers are devices that produce sound after getting a command from a
computer. Nowadays, speakers come with wireless technology also like Bluetooth
speakers.
iv. Projector
Projectors are optical devices that have the work to show visuals on both types of
screens, stationary and moving both. It helps in displaying images on a big screen.
Projectors are generally used in theatres, auditoriums, etc.
v. Plotter
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
Plotter is a device that helps in making graphics or other images to give a real
view. A graphic card is mandatorily required to use these devices. These are the
pen-like devices that help in generating exact designs on the computer.
vi. Headphones
Headphones are just like a speaker, which is generally used by a single person or it
is a single-person usable device and is not commonly used in large areas. These
are also called headsets having a lower sound frequency.
vii. Facsimile
A facsimile is a fax machine that consists of a scanner and printer, where the
scanner works as an input device and the printer works as an output device.
b. Memory
It is used to store data/information and instructions. It is a data storage unit or a data storage
device where data is to be processed and instructions required for processing are stored.
In general, computer memory is of three types:
Primary memory
Secondary memory
Cache memory
Primary Memory
It is also known as the main memory of the computer system. It is used to store data
and programs or instructions during computer operations. It uses semiconductor technology
and hence is commonly called semiconductor memory.
Primary memory is of two types:
RAM (Random Access Memory): It is a volatile memory. Volatile memory stores information
based on the power supply. If the power supply fails/ interrupted/stopped, all the data and
information on this memory will be lost. RAM is of two types:
SRAM (Static RAM): SRAM uses transistors and the circuits of this memory are
capable of retaining their state as long as the power is applied.
DRAM (Dynamic RAM): DRAM uses capacitors and transistors and stores the data
as a charge on the capacitors. It needs refreshing of charge on capacitor after a
few milliseconds. This memory is slower than SRAM.
ROM (Read Only Memory): It is a non-volatile memory. Non-volatile memory stores
information even when there is a power supply failed/ interrupted/stopped.
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
CD – ROM
It’s called compact disk.
Information is written to the disc by using a controlled laser beam to burn pits on the disc
surface.
It has a highly reflecting surface, which is usually aluminum.
WORM-(WRITE ONCE READ MANY)
A user can only write data once.
The information is written on the disc using a laser beam.
It is possible to read the written data as many times as desired.
They keep lasting records of information but access time is high.
It is possible to rewrite updated or new data to another part of the disc.
Data that has already been written cannot be changed.
DVDs
The term “DVD” stands for “Digital Versatile/Video Disc,” and there are two sorts of DVDs:
DVDR (writable)
DVDRW (Re-Writable)
DVD-ROMS (Digital Versatile Discs): These are read-only memory (ROM) discs that can be
used in a variety of ways. When compared to CD-ROMs, they can store a lot more data. It’s
an optical memory that can read and write data.
DVD-R: DVD-R is a writable optical disc that can be used just once.
Cache Memory
It is a type of high-speed semiconductor memory that can help the CPU run faster. Between the
CPU and the main memory, it serves as a buffer.
c. Processor
The full form of CPU is Central Processing Unit. It is a brain of the computer. All types of data
processing operations and all the important functions of a computer are performed by the CPU.
Parts of CPU
Now, the CPU consists of 3 major units, which are:
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
1. Registers/Memory Unit
2. Control Unit
3. ALU(Arithmetic Logic Unit)
most important type of system software in a computer system. Examples of Operating Systems
are Windows, Linux, Mac OS, etc.
Application Software
Programs created to carry out particular duties or functions are referred to as application
software. Word processors,
Device Drivers
Device drivers are software applications that connect and interact with hardware devices on
behalf of the operating system. They serve as translators.
Compiler
Compiler is a translator which is used to convert programs in high-level language to low-level
language. It translates the entire program and also reports the errors in source program
encountered during the translation.
Interpreter
Interpreter is a translator which is used to convert programs in high-level language to low-level
language. Interpreter translates line by line and reports the error once it encountered during the
translation process.
It directly executes the operations specified in the source program when the input is given by the
user.
It gives better error diagnostics than a compiler.
Differences between compiler and interpreter
Firmware
Software that is integrated with hardware devices is known as firmware. During system startup, it
initializes hardware and offers low-level control.
UNIX: An Overview
UNIX is a powerful Operating System initially developed by Ken Thompson, Dennis Ritchie at
AT&T Bell laboratories in 1970. It is prevalent among scientific, engineering, and academic
institutions due to its most appreciative features like multitasking, flexibility, and many more. In
UNIX, the file system is a hierarchical structure of files and directories where users can store and
retrieve information using the files.
Hardware -
This layer of UNIX consists of all hardware-related information in the UNIX environment.
Kernel -
The core of the operating system that's liable for maintaining the full functionality is named the
kernel. The kernel of UNIX runs on the particular machine hardware and interacts with the
hardware effectively.
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
The Shell -
The Shell is an interpreter that interprets the command submitted by the user at the terminal, and
calls the program you simply want.
Types of Shell in UNIX System:
o Bourne Shell: This Shell is simply called the Shell. It was the first Shell for UNIX OS. It is
still the most widely available Shell on a UNIX system.
o C Shell: The C shell is another popular shell commonly available on a UNIX system. The
C shell was developed by the University of California at Berkeley and removed some of
the shortcomings of the Bourne shell.
o Korn Shell: This Shell was created by David Korn to address the Bourne Shell's user-
interaction issues and to deal with the shortcomings of the C shell's scripting quirks.
Application Programs Layer -
It is the outermost layer that executes the given external applications. UNIX distributions typically
come with several useful applications programs as standard. For Example: emacs editor, StarOffice,
xv image viewer, g++ compiler etc.
$ mv text1 text2
o rm: This command is used to remove directories and files.
o mkdir: It creates a directory.
o cd: It changes the directory.
o pwd: It prints the current working directory.
o ps: It shows a snapshot of every current process.
o clear: It clears the terminal screen.
Algorithm:
An algorithm is a process or set of rules which must be followed to complete a particular task.
This is basically the step-by-step procedure to complete any task.
Characteristics of Algorithm
1. An algorithm should be defined clearly.
2. An algorithm should produce at least one output.
3. An algorithm should have zero or more inputs.
4. An algorithm should be executed and finished in finite number of steps.
5. An algorithm should be basic and easy to perform.
6. Each step started with a specific indentation like, “Step-1”,
7. There must be “Start” as the first step and “End” as the last step of the algorithm.
Step 9: Print B
Step 10: Else C is greater
Step 11: Print C
Step 12: End
BEGIN
NUMBER A, B, C
INPUT A
INPUT B
INPUT C
IF A>B
IF A>C THEN
OUTPUT “A is greatest”
ELSE
OUTPUT “C is greatest”
ENDIF
ELSE
IF B > C THEN
OUTPUT “B is greatest”
ELSE
OUTPUT “C is greatest”
ENDIF
ENDIF
END
Flowchart:
A flowchart is a picture of the separate steps of a process in sequential order.
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
{
int A,B,C;
printf("Input A:");
scanf("%d",&A);
printf("Input B:");
scanf("%d",&B);
printf("Input C:");
scanf("%d",&C);
if(A>B)
{
if(A>C)
{
printf("A is greatest");
}
else
{
printf("C is greatest");
}
}
else
{
if(B>C)
{
printf("B is greatest");
}
else
{
printf("C is greatest");
}
}
}
Types of Errors in C
There are five different types of errors in C.
Syntax Error
Run Time Error
Logical Error
Semantic Error
Linker Error
1. Syntax Error
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
Syntax errors occur when a programmer makes mistakes in typing the code's syntax correctly or
makes typos. Syntax errors are sometimes also called compilation errors because they are always
detected by the compiler. Generally, these errors can be easily identified and rectified by
programmers.
The most commonly occurring syntax errors in C language are:
Missing semi-colon (;)
Missing parenthesis ({})
Assigning value to a variable without declaring it
2. Runtime Error
Errors that occur during the execution (or running) of a program are called Runtime Errors. These
errors occur after the program has been compiled successfully.
Runtime errors can be a little tricky to identify because the compiler cannot detect these errors.
They can only be identified once the program is running. Some of the most common run time
errors are: number not divisible by zero, array index out of bounds, string index out of bounds,
etc.
3. Logical Error
Sometimes, we do not get the output we expected after the compilation and execution of a
program. Even though the code seems error free, the output generated is different from the
expected one. These types of errors are called Logical Errors.
4. Semantic Error
Errors that occur because the compiler is unable to understand the written code are called
Semantic Errors. A semantic error will be generated if the code makes no sense to the compiler,
even though it is syntactically correct.
Object code is the output of a compiler after it processes the source code. The object code is
usually a machine code, which can be understood directly by a specific type of CPU (central
processing unit).
Executable code (also called the Binary code) is the output of a linker after it processes the object
code.
Note:
Semester-1 B.Tech.-ESC 103 Introduction to UNIX and C Programming
______eof_Module1________