C Notes - 1
C Notes - 1
Being a modern-day kid you must have used, seen, or read about computers. This is
because they are an integral part of our everyday existence. Be it school, banks, shops,
railway stations, hospital or your own home, computers are present everywhere, making
our work easier and faster for us. As they are such integral parts of our lives, we must
know what they are and how they function. Let us start with defining the term computer
formally.
The literal meaning of computer is a device that can calculate. However, modern
computers can do a lot more than calculate. Computer is an electronic device that
receives input, stores or processes the input as per user instructions and provides output
in desired format.
Input-Process-Output Model
Computer input is called data and the output obtained after processing it, based on
user’s instructions is called information. Raw facts and figures which can be processed
using arithmetic and logical operations to obtain information are called data.
Characteristics of Computer
To understand why computers are such an important part of our lives, let us look at
some of its characteristics −
• Speed − Typically, a computer can carry out 3-4 million instructions per
second.
• Accuracy − Computers exhibit a very high degree of accuracy. Errors that
may occur are usually due to inaccurate data, wrong instructions or bug in
chips – all human errors.
• Reliability − Computers can carry out same type of work repeatedly
without throwing up errors due to tiredness or boredom, which are very
common among humans.
• Versatility − Computers can carry out a wide range of work from data entry
and ticket booking to complex mathematical calculations and continuous
astronomical observations. If you can input the necessary data with correct
instructions, computer will do the processing.
• Storage Capacity − Computers can store a very large amount of data at a
fraction of cost of traditional storage of files. Also, data is safe from normal
wear and tear associated with paper.
Booting
Starting a computer or a computer-embedded device is called booting. Booting takes
place in two steps −
• Desktop
• Laptop
• Tablet
• Server
• Mainframe
• Supercomputer
Let us look at all these types of computers in detail.
Desktop
Desktop computers are personal computers (PCs) designed for use by an individual at
a fixed location. IBM was the first computer to introduce and popularize use of desktops.
A desktop unit typically has a CPU (Central Processing Unit), monitor, keyboard and
mouse. Introduction of desktops popularized use of computers among common people
as it was compact and affordable.
Riding on the wave of desktop’s popularity many software and hardware devices were
developed specially for the home or office user. The foremost design consideration here
was user friendliness.
Laptop
Despite its huge popularity, desktops gave way to a more compact and portable
personal computer called laptop in 2000s. Laptops are also called notebook
computers or simply notebooks. Laptops run using batteries and connect to networks
using Wi-Fi (Wireless Fidelity) chips. They also have chips for energy efficiency so that
they can conserve power whenever possible and have a longer life.
Modern laptops have enough processing power and storage capacity to be used for all
office work, website designing, software development and even audio/video editing.
Tablet
After laptops computers were further miniaturized to develop machines that have
processing power of a desktop but are small enough to be held in one’s palm. Tablets
have touch sensitive screen of typically 5 to 10 inches where one finger is used to touch
icons and invoke applications.
Keyboard is also displayed virtually whenever required and used with touch strokes.
Applications that run on tablets are called apps. They use operating systems by Microsoft
(Windows 8 and later versions) or Google (Android). Apple computers have developed their
own tablet called iPad which uses a proprietary OS called iOS.
Server
Servers are computers with high processing speeds that provide one or more services
to other systems on the network. They may or may not have screens attached to them.
A group of computers or digital devices connected together to share resources is called
a network.
Servers have high processing powers and can handle multiple requests simultaneously.
Most commonly found servers on networks include −
Mainframe
Mainframes are computers used by organizations like banks, airlines and railways to
handle millions and trillions of online transactions per second. Important features of
mainframes are −
• Big in size
• Hundreds times Faster than servers, typically hundred megabytes per
second
• Very expensive
• Use proprietary OS provided by the manufacturers
• In-built hardware, software and firmware security features
Supercomputer
Supercomputers are the fastest computers on Earth. They are used for carrying out
complex, fast and time intensive calculations for scientific and engineering applications.
Supercomputer speed or performance is measured in teraflops, i.e. 1012 floating point
operations per second.
Chinese supercomputer Sunway TaihuLight is the world’s fastest supercomputer with
a rating of 93 petaflops per second, i.e. 93 quadrillion floating point operations per
second.
Most common uses of supercomputers include −
• System Software
• Application Software
• Utility Software
Let us discuss them in detail.
System Software
Software required to run the hardware parts of the computer and other application
software are called system software. System software acts as interface between
hardware and user applications. An interface is needed because hardware devices or
machines and humans speak in different languages.
Machines understand only binary language i.e. 0 (absence of electric signal) and 1
(presence of electric signal) while humans speak in English, French, German, Tamil, Hindi
and many other languages. English is the pre-dominant language of interacting with
computers. Software is required to convert all human instructions into machine
understandable instructions. And this is exactly what system software does.
Based on its function, system software is of four types −
• Operating System
• Language Processor
• Device Drivers
Operating System
System software that is responsible for functioning of all hardware parts and their
interoperability to carry out tasks successfully is called operating system (OS). OS is
the first software to be loaded into computer memory when the computer is switched
on and this is called booting. OS manages a computer’s basic functions like storing data
in memory, retrieving files from storage devices, scheduling tasks based on priority, etc.
Language Processor
As discussed earlier, an important function of system software is to convert all user
instructions into machine understandable language. When we talk of human machine
interactions, languages are of three types −
• Machine-level language − This language is nothing but a string of 0s and
1s that the machines can understand. It is completely machine dependent.
• Assembly-level language − This language introduces a layer of
abstraction by defining mnemonics. Mnemonics are English like words or
symbols used to denote a long string of 0s and 1s. For example, the word
“READ” can be defined to mean that computer has to retrieve data from
the memory. The complete instruction will also tell the memory address.
Assembly level language is machine dependent.
• High level language − This language uses English like statements and is
completely independent of machines. Programs written using high level
languages are easy to create, read and understand.
Program written in high level programming languages like Java, C++, etc. is
called source code. Set of instructions in machine readable form is called object
code or machine code. System software that converts source code to object code is
called language processor. There are three types of language interpreters−
• Assembler − Converts assembly level program into machine level
program.
• Interpreter − Converts high level programs into machine level program line
by line.
• Compiler − Converts high level programs into machine level programs at
one go rather than line by line.
Device Drivers
System software that controls and monitors functioning of a specific device on computer
is called device driver. Each device like printer, scanner, microphone, speaker, etc. that
needs to be attached externally to the system has a specific driver associated with it.
When you attach a new device, you need to install its driver so that the OS knows how
it needs to be managed.
Application Software
A software that performs a single task and nothing else is called application software.
Application software are very specialized in their function and approach to solving a
problem. So a spreadsheet software can only do operations with numbers and nothing
else. A hospital management software will manage hospital activities and nothing else.
Here are some commonly used application software −
• Word processing
• Spreadsheet
• Presentation
• Database management
• Multimedia tools
Utility Software
Application software that assist system software in doing their work is called utility
software. Thus utility software is actually a cross between system software and
application software. Examples of utility software include −
• Antivirus software
• Disk management tools
• File management tools
• Compression tools
• Backup tools
As you know, system software acts as an interface for the underlying hardware system. Here
we will discuss some important system software in detail.
Operating System
Operating system (OS) is the lifeline of computer. You connect all the basic devices like
CPU, monitor, keyboard and mouse; plug in the power supply and switch it on thinking
you have everything in place. But the computer will not start or come to life unless it has
an operating system installed in it because OS −
• Keeps all hardware parts in a state of readiness to follow user
instructions
• Co-ordinates between different devices
• Schedules multiple tasks as per priority
• Allocates resource to each task
• Enables computer to access network
• Enables users to access and use application software
Besides initial booting, these are some of the functions of an operating system −
Assembler
Assembler is a system software that converts assembly level programs to machine level
code.
Interpreter
The major advantage of assembly level language was its ability to optimize memory
usage and hardware utilization. However, with technological advancements computers
had more memory and better hardware components. So ease of writing programs
became more important than optimizing memory and other hardware resources.
In addition, a need was felt to take programming out of a handful of trained scientists
and computer programmers, so that computers could be used in more areas. This led to
development of high level languages that were easy to understand due to resemblance
of commands to English language.
The system software used to translate high level language source code into machine
level language object code line by line is called an interpreter. An interpreter takes each
line of code and converts it into machine code and stores it into the object file.
The advantage of using an interpreter is that they are very easy to write and they do not
require a large memory space. However, there is a major disadvantage in using interpreters,
i.e., interpreted programs take a long time in executing. To overcome this disadvantage,
especially for large programs, compilers were developed.
Compiler
System software that store the complete program, scan it, translate the complete
program into object code and then creates an executable code is called a compiler. On
the face of it compilers compare unfavorably with interpreters because they −
BASIS OF
ASSEMBLER COMPILER
COMPARISON
Compiler inputs is
Input Assembler inputs source code.
preprocessed source code.
C
GAS C#
Examples
GNU Java
C++
In case of interpreter, No
Code Intermediate object code is
intermediate object code is
Generation generated in case of compiler.
generated.
Python
C
Perl
COBOL
Examples VB
C#
PostScript
C++, etc
LISP etc.
Hardware
The term hardware refers to mechanical device that makes up computer. Computer
hardware consists of interconnected electronic devices that we can use to control
computer’s operation, input and output. Examples of hardware are CPU, keyboard,
mouse, hard disk, etc.
Hardware Components
Computer hardware is a collection of several components working together. Some parts
are essential and others are added advantages. Computer hardware is made up of CPU
and peripherals as shown in image below.
Software
A set of instructions that drives computer to do stipulated tasks is called a program.
Software instructions are programmed in a computer language, translated into machine
language, and executed by computer. Software can be categorized into two types −
• System software
• Application software
System Software
System software operates directly on hardware devices of computer. It provides a
platform to run an application. It provides and supports user functionality. Examples of
system software include operating systems such as Windows, Linux, Unix, etc.
Application Software
An application software is designed for benefit of users to perform one or more tasks.
Examples of application software include Microsoft Word, Excel, PowerPoint, Oracle,
etc.
Differences between Software and Hardware are sorted out below −
7 The software The hardware consists of input devices, output devices, memory,
is etc.
categorized
as operating
system,
utilities,
language
processor,
application
software, etc.
Algorithm and Flowchart
A flowchart is a blueprint that pictorially represents the algorithm and its steps. The steps of a
flowchart do not have a specific size and shape rather it is designed in different shapes and
sizes (see the image given below).
As shown in the above image, the boxes in different shapes and interconnected with arrows,
are logically making a flow chart. A flow-chart represents the general steps in a process.
Benefits of Flowchart
Let us now discuss the benefits of a flowchart.
Effective Analysis
Once the flow-chart is prepared, it becomes very simple to analyze the problem in an
effective way.
Useful in Coding
The flow-chart also helps in coding process efficiently, as it gives directions on what to
do, when to do, and where to do. It makes the work easier.
Proper Testing
Further, flowchart also helps in finding the error (if any) in program
Applicable Documentation
Last but not the least, a flowchart also helps in preparing the proper document (once
the codes are written).
Flow-Chart Symbols
The following table illustrates the symbols along with their names (used in a flow-chart)
−
Represents a group of
Predefined
statements performing one
Process/Function
processing task.
Examples of flowcharts in programming
2. Find the largest among three different numbers entered by the user.
3. Find all the roots of a quadratic equation ax2+bx+c=0
4. Find the Fibonacci series till term≤1000.
Algorithm
Before solving a problem, one should know what to do, how to do it, and what types of
steps should be taken. So, an algorithm is a step-by-step method for solving a problem.
An algorithm refers to a set of instructions that define the execution of work to get the
expected results.
To make the program work properly, we must have to properly design the algorithm.
Designing the algorithm helps to utilize the computing resources effectively.
Generally, the algorithms are written in natural language or in plain English language. We
can represent algorithms via flowcharts, pseudo code, and others.
Sometimes algorithms are difficult to understand, and it is also difficult to show looping
and branching using an algorithm. Apart from programming languages or programs, the
algorithm can be designed for any problem, as it is a step-by-step solution of a program.
Advantages of algorithm
o Algorithms are easy to write.
o There is a use of human-readable techniques to understand logic.
o For big problems, algorithms can be written with moderate steps.
Disadvantages of algorithm
o Algorithms are difficult to debug.
o It is hard to show branches and loops using an algorithm.
o Jumping (or goto statements) makes the algorithm hard to trace the problems.
Algorithm:
Step 4: If 'x' is less than 20, then go back to step 2. Otherwise, go to the next step.
Step 5: Exit.
Basic An algorithm is a step-by-step method for The Flowchart is the most widely
solving some problem. An algorithm refers used graphical representation of
to a set of instructions that define the an algorithm and procedural
execution of work to get the expected design workflows. It uses various
results. symbols to show the operations
and decisions to be followed in a
program.
Implementation There are no rules employed for algorithms. Predefined rules are
implemented for flowcharts.
Symbols used It uses plain text, which is written in plain It uses symbols such as
English language. parallelogram, rectangle,
diamond, etc.
Nature Algorithms are the program's pseudocode. Flowcharts are the graphical
representation of logic.
Each programming language contains a unique set of keywords and syntax, which are
used to create a set of instructions. Thousands of programming languages have been
developed till now, but each language has its specific purpose. These languages vary in
the level of abstraction they provide from the hardware. Some programming languages
provide less or no abstraction while some provide higher abstraction. Based on the levels
of abstraction, they can be classified into two categories:
o Low-level language
o High-level language
o The image which is given below describes the abstraction level from hardware. As
we can observe from the below image that the machine language provides no
abstraction, assembly language provides less abstraction whereas high-level
language provides a higher level of abstraction.
Low-level language
The low-level language is a programming language that provides no abstraction from the
hardware, and it is represented in 0 or 1 forms, which are the machine instructions. The
languages that come under this category are the Machine level language and Assembly
language.
Machine-level language
The machine-level language is a language that consists of a set of instructions that are in
the binary form 0 or 1. As we know that computers can understand only machine
instructions, which are in binary digits, i.e., 0 and 1, so the instructions given to the
computer can be only in binary codes. Creating a program in a machine-level language is
a very difficult task as it is not easy for the programmers to write the program in machine
instructions. It is error-prone as it is not easy to understand, and its maintenance is also
very high. A machine-level language is not portable as each computer has its machine
instructions, so if we write a program in one computer will no longer be valid in another
computer.
The different processor architectures use different machine codes, for example, a PowerPC
processor contains RISC architecture, which requires different code than intel x86
processor, which has a CISC architecture.
Assembly Language
The assembly language contains some human-readable commands such as mov, add,
sub, etc. The problems which we were facing in machine-level language are reduced to
some extent by using an extended form of machine-level language known as assembly
language. Since assembly language instructions are written in English words like mov,
add, sub, so it is easier to write and understand.
The assembly language code is not portable because the data is stored in computer
registers, and the computer has to know the different sets of registers.
The assembly code is not faster than machine code because the assembly language
comes above the machine language in the hierarchy, so it means that assembly language
has some abstraction from the hardware while machine language has zero abstraction.
The machine-level language comes at the lowest The assembly language comes above the machine
level in the hierarchy, so it has zero abstraction language means that it has less abstraction level
level from the hardware. from the hardware.
It cannot be easily understood by humans. It is easy to read, write, and maintain.
The machine-level language is written in binary The assembly language is written in simple English
digits, i.e., 0 and 1. language, so it is easily understandable by the
users.
It does not require any translator as the machine In assembly language, the assembler is used to
code is directly executed by the computer. convert the assembly code into machine code.
High-Level Language
The high-level language is a programming language that allows a programmer to write
the programs which are independent of a particular type of computer. The high-level
languages are considered as high-level because they are closer to human languages than
machine-level languages.
When writing a program in a high-level language, then the whole attention needs to be
paid to the logic of the problem.
o The high-level language is easy to read, write, and maintain as it is written in English
like words.
o The high-level languages are designed to overcome the limitation of low-level
language, i.e., portability. The high-level language is portable; i.e., these languages
are machine-independent.
It requires the assembler to convert the It requires the compiler to convert the high-
assembly code into machine code. level language instructions into machine code.
The machine code cannot run on all machines, The high-level code can run all the platforms, so
so it is not a portable language. it is a portable language.
Debugging and maintenance are not easier in Debugging and maintenance are easier in a
a low-level language. high-level language.