0% found this document useful (0 votes)
29 views25 pages

POP Module 1

Bpops103 or bpops203 module 1 notes

Uploaded by

darshangowda0525
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views25 pages

POP Module 1

Bpops103 or bpops203 module 1 notes

Uploaded by

darshangowda0525
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Principles of Programming using C BPOPS203

Module – 1 – Introduction to Computer and C :

1. Introduction :
Computer is an electronic device which accepts input, processes data, stores information and produces output.

Data: Raw facts / figures are called as Data.

Information: Processed data is called as Information.

2. Characteristics of Computer :
Economical

Deligence Computer Large Memory


Speed

Speed : Computers can perform millions of operations per second. The speed of computers is usually given in
nanoseconds and picoseconds, where 1 nanosecond =1 10−9seconds and 1 picosecond = 1 10−12seconds.

Accuracy: A computer is a very fast, reliable, and robust electronic device. It always gives accurate results,
provided the correct data and set of instructions are input it. Hence, in the event of an error, it is the user who has
fed the incorect data/program is responsible. This clearly means that the output generated by a computer depends
on the given instructions and input data. it the input data is wrong, then the output will also be errorenous. In
computer terminology, this is known as garbage-in, garbage - out (GIGO).

Large Memory: Computers also have internal or primary memory (storage space) as well as external or
secondary memory. While the internal memory of computers is very expensive and limited in size, the

Information Science and Engineering, JIT


Principles of Programming using C BPOPS203

secondary storage is cheaper and of bigger capacity. Primary Memory – RAM , Secondary Memory – DVD’s,
CD’s.

NO IQ: Although the trend today si to make computers intelligent by inducing artificial inteligence (AI) ni
them, they stil do not have any decision-making abilities fo their own. They need guidance to perform various
tasks.

Economical: Today, computers are considered as short-term investments for achieving long-term gains. Using
computers also reduces manpower requirements and leads to elegant and efficient way of performing various
tasks. Hence, computers save time, energy, and money.

Automation: Besides being very fast and accurate, computers are automatable devcies that can perform a task
without any user Intervention. The user just needs to assign the task to the computer, after which it automatically
controls different devices attached to it and executes the program instructions.

Deligance: Unlike humans , computers never get tired of a repetitive task. It can continually work for hours
without creating errors. Even if a large number of executions need to be executed, each and every execution
requires same duration and is executed with the same accuracy.

Versatility: Versatility is the quality of being flexible. Today computers are used in our daily life in different
fields. For example, they are used as personal computers (PCs) for home use, for business-oriented tasks, weather
forecasting, space exploration, teaching, railways, banking, medicine and so on, indicating that computers can
perform different tasks simultaneously.

3. Generations of Computers:
Each generation is defined by a significant technological development that changes fundamentally how
computers operate – leading to more compact, less expensive, but more powerful, efficient and robust
machines.

• 1940 – 1956: First Generation – Vacuum Tubes:

The computers produced during the period 1946-1959 with the them technology are regarded as
the first generation computer. These computers were manufactured with the vacuum tubes,
electronic values, triodes, and diodes etc. as their basic elements. These tubes were used in the
arithmetic and logical operations. UNIVAC and ENIAC machines – the UNIVAC is the first every
commercial computer which was purchased in 1951 by a business – the US Census Bureau.

Advantages:

They were capable of making arithmetic and logical operations.

They used the electronic values in place of the key punch machines or the unit record machines.

Disadvantages :

They were too big in size, very slow, low level of accuracy and reliability

They consumed lot of electricity, generated a lot of heat and break down frequently.
Information Science and Engineering, JIT
Principles of Programming using C BPOPS203

They had very low storage capacity and used machine language.

• 1956 – 1963: Second Generation – Transistors

The computers produced during the period 1959-1965 with technology are known as second
generation computers. These computers used transistors in place of vacuum tubes as their basic
elements to perform all computational and logical works. About the same time high level programming
languages were being developed (early versions of COBOL and FORTRAN).

Advantages:

They required very small space, they were very fast and reliable and dependable.

They used less power and dissipated less heat and had large storage capacity.

They used better peripheral devices like card readers and printer etc.

Disadvantages:

They did not have any operating system and used assembly language.

They lacked in intelligent and decision making and needed constant up keep and maintainance.

They handled data processing in batch mode only.

• 1964 – 1971: Third Generation – Integrated Circuits

The computers developed during the period 1965-1970 are branded as the third generation
computers. The significant features of these computers were that they were built with monolithic
integrated circuits each of which consisted of thousands of transistors and other electronic
components on a single crystal. By virtue of feature known as time sharing, the computer could run
programs invoked by multiple users. The existing programming languages were supplemented by
BASIC, C, C++ and Java.

Advantages:

The size was very small in comparison less costly and built with thousands of transistor which
were very cheap.

They used faster better device for storage called auxiliary backing or secondary storage.

They used operating system for better resource management and used the concept of time sharing
and multiple programming.

Disadvantages:

They created lot of problems to the manufacturers at their initial stages.

They lacked thinking power and decision making capability.

They could not provide any insight into their internal working.

Information Science and Engineering, JIT


Principles of Programming using C BPOPS203

• 1972 – 2010: Fourth Generation – Microprocessors

The computer that came to the scene with improved technology during the period 1970-1985 is
marked as the fourth generation computers. They used large scale integrated circuits and very large
integrated circuits in the form of micro processor in their memory.

These computers enlaced millions of transistors and other electronic components on a single silicon
chip.

A micro processor is a single chip which itself can perform the controlling arithmetic and logical
functions of a computer that too at a fast speed.

Advantages:

They were very small in size and cost of operation was very less.

They were very compact faster and reliable as they used very large scale integrated circuits.

They were capable of facilitating the interactive on line remote programming by which one sitting
at the distant place can get his programs executed by centrally located computer.

Disadvantages:

They are less powerful and had less speed than the main frame computers.

They lacked thinking power and decision making ability.

They had less storage capacity and needed further improvement.

• 2010- : Fifth Generation – Artificial Intelligence

The computers that are emerging after 1985 with further improved technology are considered as the
fifth generation computers. These machines are designed to incorporate “Artificial Intelligence” and
used stored reservoirs of knowledge to make expert judgments and decision like human begins.
They are also designed to process non numerical information like pictures and graphs using them
very large scale integrated circuits.

Advantages:

They are oriented towards integrated data base development to provide decision models.

They faster very cheap and have the highest possible storage capacity.

They have thinking power and decision making capability and thereby they will be able to aid the
executives in the management.

Disadvantages:

They need very low level languages they may replace the human force and cause grievous
unemployment problems.

They may make the human brains dull are doomed.

Information Science and Engineering, JIT


Principles of Programming using C BPOPS203

4. Types of Computers:
Apart from being classified by generations, computers can also be categorized by their size. The size of a
computer is often an indirect indication of its capabilities.

Super Computers:- These are huge machines having most powerful and fast processors. A super computer has
multiple CPUs for parallel data processing. Speed is measured in terms of flops(floating point operations per
second)

super computers are too powerful to be used for transaction processing. They are mainly used in the areas like
weather forecasting, analysis of geological data, nuclear simulation and space exploration. They are also used to
solve complex scientific problems. Super computers have enormous storage and use huge amounts of power and
generate a lot of heat. because of the exorbitant cost, they are mainly used by government agencies

Main frames:-

Mainframe is very large in size and is an expensive computer capable of supporting hundreds or even thousands
of users simultaneously. Mainframe executes many programs concurrently and supports many simultaneous
execution of programs.

Mainframes are used to handle data and application related to the organisation as a whole.

Today, main frames are employed to handle online transactions, the capability to handle large amount of data
makes the main frame suitable for use in government, banks and financial institutions and large corporations.

Minicomputers:-

Computer that is smaller, less expensive, and less powerful than a mainframe or supercomputer but more
expensive and more powerful than a personal computer. Minicomputers are used for scientific and engineering
computations, business-transaction processing, file handling, and database management, and are often now
referred to as small or midsize servers.

Microcomputers:-

An electronic device with a microprocessor as its central processing unit (CPU). Microcomputer was formerly a
commonly used term for personal computer, particularly any of a class of small digital computer whose CPU is
contained on a single integrated semiconductor chip. Thus, a microcomputer uses a single microprocessor forits
CPU, which performs all logic and arithmetic operations. The system also contains a numberof associated
semiconductor chips that serve as the main memory for storing program instructions and data and as interfaces
for exchanging data of this sort with peripheral equipment—namely, input/output devices (e.g., keyboard, video
display, and printer)

and auxiliary storage units. Smaller microcomputers first marketed in the 1970s contain a single chip on which all
CPU, memory, and interface circuits are integrated.

They are mainly used for engineering and scientific applications and for software development along with word
processing, desktop publishing, internet browsing and can also handle audio, video and image files

Smartphones and Embedded Computers:-

Smartphones are a class of mobile phones and of multi-purpose mobile computing devices. They are
distinguished from feature phones by their stronger hardware capabilities and extensive mobile operating

Information Science and Engineering, JIT


Principles of Programming using C BPOPS203

systems, which facilitate wider software, internet (including web browsing over mobile broadband ), and
multimedia functionality (including music, video, cameras and gaming ), alongside core phone functions such
asvoice calls and text messaging. Smartphones typically contain a number ofmetal-oxide-semiconductor (MOS)
integrated circuit (IC) chips, include various sensors that can be leveraged by their software,and support wireless
communications protocols (such as Bluetooth. Wi-Fi or satellite navigation) .

Embedded computers are everywhere. They are in phones, microwaves, airplanes,automobiles, calculators...
The list goes on and on. An embedded computer, which is an integral component of most embedded system, is a
combination of hardware and software thatis designated to perform a highly specific function. Because the
software in embeddedcomputers is designed to only execute certain tasks, the computer’s software in one device
canbe totally distinct from that of another. The hardware of an embedded computer is also speciallydesigned to
withstand stresses in its intended environment.

5. BITS, BYTES AND WORDS :


• Computer can understand only two states: 0 and 1.
• A digit can have only two states or values known as a binary digit, abbreviated as bit (b).
• The name byte (B) was coined to represent eight bits.
• The byte is the standard unit of measurement of computer memory, data storage and transmission
speed.
• The CPU handles memory data in larger units, called words and it is usually even multiple of
bytes (two bytes, four bytes etc.).
• When referred to a computer it has 32-bit (4 bytes) machine i.e., size of word is 32 bits.

6. INSIDE THE COMPUTER:-


• CPU - Central Processing Unit :

The brain of the computer is the Central Processing Unit (CPU) represented by a single chip
on a PC. The CPU carries out every instruction stored in a program while interacting with other agencies as and
when necessary. Most of the work is done by the Arithmetic and Logic unit (ALU) which is the integral part of
the CPU.

The CPU needs both fast and slow memory to work with. Fast memory is represented by primary memory known
as Random Access Memory (RAM). It is divided into number of contiguously numbered cells. The

number represents the address of the cell. The primary memory is used for storing instructions and data of the
program currently in execution.

A central processing unit (CPU), also called a central processor or main processor, is the electronic circuitry
within a computer that executes instructions that make up a computer program . The CPU performs basic
airthmetic , logic, controlling, and input/output (I/O) operations specified by the instructions in the program.

CPU itself has following three components. Memory or Storage Unit, Control Unit and ALU(Arithmetic
Logic Unit).

Information Science and Engineering, JIT


Principles of Programming using C BPOPS203

• The ALU is a “super calculator” carrying out all arithmetic tasks and Boolean operations.
• The CU controls the way data is moved between the various components of computer.
• The CPU uses a few high-speed registers to store the current instruction and its data. One of the registers,
program counter, stores the address of next instruction to be executed.
• The CPUs are rated in GHz (gigahertz).
• Input Unit: It is used to give the input that is data to the computer. It is done with the help of input
devices. Ex: Mouse, Keyboard
• Output Unit: It is used to receive the output (information) from the computer. It is done
• with the help of output devices. Ex: Printer, Speaker.
• Memory: Collection of chips on motherboard, where all computer processing and program instructions
are stored. There are two types: Primary Memory and Secondary Memory.

• Primary Memory:

Primary memory is the main memory, which stores data and programs, which are currently
needed by CPU.The size is less than the secondary memory and it is costly.
1. RAM (Random Access Memory): It is the main memory, where the user can write information
intoRAM and read information from it. It is accessible to users. The RAM is randomly accessible by
user.It is a volatile memory, which means the data, or information is retained as long as power
supply is ON. There are two types of RAM: SRAM and DRAM.
2. ROM (Read Only Memory): It is a permanent memory that can be read but not written. It is a
nonvolatile memory, which means the data or information is retained even power supply is not
there.It contains a startup program BIOS (Basic Input Output System) which transfers control to
OS.

Information Science and Engineering, JIT


Principles of Programming using C BPOPS203

• Secondary Memory:
Secondary memory is not directly connected to CPU. It exists inside the machine and also
externally. It is a non-volatile, offline and long-term storage memory. It is slower, cheaper than
primary memory but the capacity is higher.
1. Hard disk/ Hard drive/ Fixed disk: It is the oldest secondary storage device. It has more
capacity but, the cost is less comparatively. It is commonly present in laptop with 500GB and
desktop with 1TB. It contains a spindle, which holds one or more platters made up of non-
magnetic material. It hastwo surfaces which is coated with magnetic material. Each surface has
serially numbered tracks and further broken into sectors or blocks. The disk runs with the speed
of 5400 and 7200 rpm.
2. Magnetic tape: The magnetic tape is made up of plastic film with one side coated with magnetic
material. It supports 1 TB or more, but 200 TB are also expected. The device is not fully portable
though because, a separate tape drive is required. The data is accessed sequentially. This makes
it unsuitable for backup.
3. Magnetic tape: The magnetic tape is made up of plastic film with one side coated with magnetic
material. It supports 1 TB or more, but 200 TB are also expected. The device is not fully portable
though because, a separate tape drive is required. The data is accessed sequentially. This makes
it unsuitable for backup.
4. Optical Disks (CD-ROM, DVD ROM, Blu-ray Disk): It is non-volatile read-only memory. The CD-
ROM and DVD-ROM, can hold large volumes of data (700MB to 8.5 GB). The Blu-ray disk has the
capacity upto 50 GB. A laser beam in their drives controls the read and write operations.

7. INPUT DEVICES :
The Keyboard: A keyboard is defined as the set of typewriter-like keys that enables you to enter data into a
computer or other devices. Computer keyboards are similar to electric- typewriters but contain additional typing
keys. The standard selection of keys can be classified as Alphanumeric keys, Punctution keys and special keys.
The standard layout of letters, numbers, and punctuation is known as QWERTY because the first six typing keys
on the top row of letters spell QWERTY. The QWERTY keyboard was designed in the 1800s for mechanical
typewriters and was actually designed to slow typists down to avoid jamming the keys on mechanical units.

Pointing Devices: A pointing device, or sometimes called a pointing tool, is a hardware input device that allows
the user to move the mouse cursor in a computer program or GUI operating system. Using a pointing device, you
can point at or manipulate any object or text on the screen. For example, using a pointing device you could point
at and select an icon from a list of icons.

The Scanner: A scanner is an input device that scans documents such as photographs and pages of text. When a
document is scanned, it is converted into a digital format. This creates an electronic version of the document that
can be viewed and edited on a computer.

8. OUTPUT DEVICES :

Information Science and Engineering, JIT


Principles of Programming using C BPOPS203

The Monitor: A computer monitor is an output device that displays information in pictorial form. A monitor
usually comprises the visual display, circuitry, casing, and power supply. The display device in modern monitors
is typically a thin film transistor liquid crystal display (TFT-LCD) with LED backlighting having replaced cold-
cathode fluorescent lamp (CCFL) backlighting. Older monitors used a cathode ray tube (CRT). Monitors
areconnected to

the computer via VGA, Digital Visual Interface (DVI), HDMI, DisplayPort, Thunderbolt, low-voltage
differential signaling (LVDS)or other proprietary connectors and signals.

Impact Printers: An impact printer is a type of printer that operates by striking a metal or plastic head against an
ink ribbon. The ink ribbon is pressed against the paper, marking the page with the appropriate character , dot,
line, or symbol.

Dot matrix Printer: A dot matrix printer (DMP) is a type of printer which uses pins impacting an ink ribbon to
print. These printers are generally considered outdated, as they cannot create high-quality prints and are costly as
well. they can be used to print multiple copies of text at the same time with the help of carbon copying.
Therefore, they are mostly used in places where multipart forms are required. In a dot matrix printer, the
characters and letters are formed by a matrix of dots. A print head, which has many pins in it, moves in the
required direction and strikes against a cloth ribbon which is soaked in ink, making a mark on the paper. The dots
are spaced closely in a particular shape to make the intended character. This looks quite similar to the printing
mechanism of typewriters and daisy wheel printers. However, dot matrix printers are different in the sense that
many different characters and graphics can be printed. A character printed by a DMP is actually an accumulation
of many such dots on a small area of the paper.

Daisy Wheel Printer: A type of printer that produces letter-quality type. A daisy-wheel printer works on the
same principle as a ball-head typewriter. The daisy wheel is a disk made of plastic or metal on which characters
stand out in relief along the outer edge. To print a character, the printer rotates the disk until the desired letter is
facing the paper. Then a hammer strikes the disk, forcing the character to hit an ink ribbon, leaving an impression
of the character on the paper. You can change the daisy wheel to print different fonts. Daisy-wheel printers
cannot print graphics , and in general they are noisy and slow, printing from 10 to about 75 characters per second.

Line Printer: A line printer is an impact printer which makes use of a continuous feed of paper and prints one
line of text at a time. A line printer is also known as a bar printer. High speed is one of the advantages of line
printers. Compared to other printers, they are low in cost and more durable. The consumables of line printers are
less harmful to the environment and are less costly as well. The print quality is mostly low and they cannot print
graphics. Line printers are very noisy while operating and may need soundproofing.

Non-Impact Printers: These address the drawbacks of Impact printers. The Non-impact printers are
generally much quieter than impact printers and produce documents of high resolution.

Laser Printer: The printers laser beams your print onto a metal cylinder called a drum. Using static electricity,
the drum attracts powdered toner from its cartridge to the drum. The drum rolls the toner onto the paper in the
form of your print. The toner is melted onto the paper by heat from a fuser as it passes underneath. Your print
comes out of the printer

Inkjet Printer: At the heart of an ink jet printer are a large number of high-precision microscopic nozzles which
eject ink onto the paper. These nozzles are typically about 10 micrometers in diameter (roughly 1/10th of the
diameter of a human hair). It is not unusual for a home ink jet printer to contain thousands of nozzles in all,
several hundred for each color of ink. The diameter of each of these nozzles is fabricated with sub-micrometer
accuracy to achieve consistent and uniform ink drop volume, which is essential for consistent and uniform color
density on the page. For each color of ink, all of the nozzles on the carriage are typically formed in a single
fabrication step to precisely control their relative positions, which is important to achieve uniform print without
banding. In some cases, all of the nozzles for every color of ink are formed together in a single step. The nozzles
Information Science and Engineering, JIT
Principles of Programming using C BPOPS203

are all formed as orifices through a single planar sheet of a material. This material is selected for its compatibility
with the particular fabrication method chosen. The ink jet nozzles are all mounted together on a moving carriage
assembly that moves at high velocity (typically > 1 meter per second) back and forth across the paper. The
nozzles are mounted about 1 mm from the paper, and ink ejection velocities are in the range of 5 to 10 meters per
second. Ink is ejected from a nozzle by applying a pulse of pressure to the fluid ink in the supply tube, upstream
of that nozzle.

Plotters: A plotter is a printer designed for printing vector graphics. Instead of printing individual dots on the
paper, plotters draw continuous lines. This makes plotters ideal for printing architectural blueprints, engineering
designs, and other CAD drawings. There are two main types of plotters – drum and flatbed plotters. Drum
plotters (also called roller plotters) spin the paper back and forth on a cylindrical drum while the ink pens move
left and right. By combining these two directions, lines can be drawn in any direction. Flatbed plotters have a
large horizontal surface on which the paper is placed. A traveling bar draws lines on the paper as it moves across
the surface.

Most drum and flatbed plotters provide output sizes that are much larger than standardinkjet and laser printer.
The length of a document printed by a drum plotter is only limited by the size of the paper. Documents printed by
flatbed plotters are constrained to the length and width of the printing surface.

9. Designing Efficient Programs :


A programming paradigm is a fundamental style of programming that defines how the structure and basic
elements of a computer program will be built. The style of writing programs and the set of capabilities and
limitations that a particular programming language has depends no the programming paradigm it supports.

These paradigms, in sequence of their application can be classified as follows:

• Monolithic programming - emphasizes on finding a solution.


• Procedural programming - lays stress on algorithms.
• Structured programming - focuses on modules
• Object-oriented programming - emphasizes on object and classes
• Logic-oriented programming - focuses on goals usually expressed in predicate calculus.
• Rule-oriented programming - makes use of ‘if-then-else' rules for computation.
• Constraint-oriented programming - utilizes invariant relationships to solve a problem.

Software Development Life Cycle:

1. Requirement Analysis: In this phase the users expectations are gathered to know why the
program/ software has to be built. Then all the gathered requirements are analysed to arrive at the
scope ot the objective of the averall software product.
2. Design: The requirments documented in the previous phase acts as an input to the design phase. In
the design phase, a plan of actions is made before the actual development process can start. This
plan will be followed throughout the development process.
3. Implementation: In this phase, the designed algorithms are converted in to program code using
any of the high level languages. This phase is also called as construction code generation phase as
the code of the software is generated in this phase.
4. Testing: In this phase, all the modules are tested together to ensure that the overall system works
well as a whole product. In this phase software is tested using a large number of varied inputs, also
known as test data, to ensure that the software is working as expected by the users requirements
that were identified in the requirements analysis phase.
Information Science and Engineering, JIT
Principles of Programming using C BPOPS203

5. Software Deployment, Training and support: After the code is tested and the software or the
program has been approved by the users, it is installed or deployed in the production environment.
6. Maintenance: Maintenance and enhancment are ongoing activities that are done to cope with
newly discovered problems or new requirements.

Requirments Analysis

Design

Implimentation
Analysis

Testing

Software Deployment

Maintenance

Phases in software development life cycle

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

10. Program Design Tools:


• Algorithms
• Flowcharts
• Pseudocodes

Algorithm : In its purest sense, an algorithm is a mathematical process to solve a problem using a finite
number of steps. In the world of computers, an algorithm is the set of instructions that defines not just what
needs to be done but how to do it. In an algorithm,

• Each step should be numbered in a hierarchical manner,


• Every step must be complete, unambiguous and error free

Flowchart : A flowchart is a diagram that describes a process or operation. It includes multiple steps, which the
process "flows" through from start to finish. Common uses for flowcharts include developing business plans,
defining troubleshooting steps, and designing mathematical algorithms. Graphical representation of a program.

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

Pseudocode: is a detailed yet readable description of what a computer program must do, expressed in a
formally-styled natural language rather than in a programming language. Pseudocode is sometimes used as a
detailed step in the process of developing a program. It allows designers or lead programmers to express the
design in great detail and provides programmers a detailed template for the next step of writing code in a
specific programming language.

Examples:

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

11. Types of Errors:


1. Run-time Error : As the name suggests, run-time errors occur when the program is being run
executed. Such errors occur when the program performs some illegal operations like dividing a
number by zero, Lack of Memory space, Opening a file that already exist, finding square or
logarithm of negative numbers.

Run-time erors mya terminate program execution, os the code must be written in such a way
that it handles all stors of unexpected errors rather terminating ti unexpectedly.

2. Compile-time Error : As the name implies, compile-time errors occur at the time of
compilation of the program. Such errors can be further classified as follows:Syntax Errors:
Synatx errors are generated when rules of a programming language are violated.
Semantic Errors are those errors which may comply with rules of the programming language
but are not meaningful to the compiler.
3. Logical Errors : Logical errors aer errors ni the program code that result in unexpected and
undesirable output.
4. Linker Error: These errors occur when the linker is not able ot find the function definition for
a given prototype.

12. Testing and Debugging approches:


Testing is an activity that is performed to verify correct behaviour of aprogram. It is specifically
carried out with an intent to find errors. Ideally testing should be conducted at all stages of program
development.

1. Unit Test: Unit testing is applied only on a single unit or module to ensure whether it exhibits
the expected behaviour.

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

2. Integration Test: These tests are a logical extension of unit tests. In this test, two units that have
already been tested are combined into a component and the interface between them is tested.
The guiding principle is to test combinations of pieces and then gradually expanding the
component to include other modules as well.
3. System Tests: System testing checks the entire system. For example, if our program code
consists of three modules then each of the module is tested individually using unit tests and then
system test is applied to test this entire system as one system.

Debugging is an activities that includes execution testing and code correction. The main aim of debugging is
locating errors in the program code. Once the errors are located, they are then isolated and fixed to produce an
error-free code. Different approaches applied for debugging a code includes:

1. Brute-Force Method: In this technique, a printout of CPU registers and relevant memory locations is
taken, studied, and documented. It is the least efficient way of debugging a program and id generally
done when all the other methods fail.
2. Backtracking Method: It is a popular technique that is widely used to debug small applications. It
works by locating the first symptom of error and then tracing backward across the entire source code
unlit the real cause of eror is detected.
3. Cause Elimination: In this approach, a list of all possible causes of an error is developed. Then
relevant tests are carried out to eliminate each of them. If some tests indicate that particular cause may
be responsible for an error then the data are refined to isolate the error.

13. Introduction to C Programming :


Programming Languages: Before learning any language, it is important to know about
the various types of languages and their features.

It is interesting to know what the basic requirements of the programmers were and what difficulties they faced
with the existing language.

The programming languages can be classified into two types-

Low level languages :

• Machine level language : Computers can understand only binary digits 0 and 1.
• Writing a program in machine level language is a difficult task because it is not easy for
programmers to write instructions in binary code.
• Every computer has its own machine instructions, so the programs written for one computer are
not valid for other computers.
• Assembly Language : In Assembly language instructions are given in English like words such
as MOV, ADD, SUB etc. So it is easy to understand assembly programs.
• Computer can understand only 0 and 1, assembly language program must be translated into
machine language. The translator that is used for translating is called “assembler”
• Although writing programs in assembly language is a bit easier, the programmer has to know all
the low level details related with the hardware of a computer.
• In assembly language, data is stored in computer registers and each computer has different set
of registers.
• Assembly language program is also not portable.
Information Science and Engineering, JIT
Principles of Programming Using C BPOPS203

High level languages :

• High level languages are designed keeping in mind the features of portability i.e these languages
are machine independent.
• While programming in high level language, the programmer is not concerned with the low level
details.
• For translating a high level language program into machine language, compiler or interpreter is
used.
• Every language has its own compiler or interpreter.
• Translator : Translator will translating a high level language program into machine language.
• Three types of translators
• Assembler – It is used to convert the low level language(assembly language) into machine
language.
• Compiler- Compiler searches all the errors of program and lists them.
• Interpreter – Checks the errors of program statement by statement.
• In C GCC is an open-source compiler and comes free with all flavors of linux and unix
distributions.

HISTORY OF C

C is a general purpose, procedural, structured computer programming language developed by Dennis Ritchie in
the year 1972 at AT&T Bell Labs.

In earlier days, every language was designed for some specific purpose.

Example- FORTRAN(Formula Translator) was used for scientific and mathematical applications.
COBOL(Common Business Oriented Language) was used for business applications.

C language was developed on UNIX and was invented to write UNIX system software. C is a successor of B
language.
There are different C standards: K&R C std, ANSI C, ISO C.

After learning C, it will be much easier to learn other programming languages like Java, Python, etc.

Characteristics of C:

• C is easy to learn.
• C is a general purpose language - C programming can be used to develop operating systems,
embedded systems, databases, and so on.
• C is a structured and procedural language - Instructions in a C program are executed step by step.
• It is portable - You can move C programs from one platform to another, and run it without any or
minimal changes.
• Speed - C programming is faster than most programming languages like Java, Python, etc
• It can extend itself

Examples of C:

• Operating system
Information Science and Engineering, JIT
Principles of Programming Using C BPOPS203

• Language compilers
• Assemblers
• Text editors
• Databases

Structure of C program:

Every c program is made up of one or more pre-processor commands, global declarations, and one or more
functions.

Documentation section :consists of a set of comment line giving the name of the program, the author, and
other details. Compiler ignores these comments when it translates the program into executable code.

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

C uses 2 different formats


1. Block comments /*this is multi line comments*/

2. Line comments //this is single line comments

The Link section: provides instruction to the compiler to link functions from system library. This Section is
also called as pre-processor Statements.

The definition section: defines all symbolic constants.

Global Declaration section: there are some variables that are used in more than on function, such a variable
are called global variable and are declared in the global declaration section that is outside of all functions. This
section also defines user defined functions.

Every C program must have one main () function section. This section contains two parts declaration part and
executable part
Declaration part declares all the variables used in the executable part
There is at least one statement in an executable part. These two part must appear at the beginning of the brace
and ends at the closing brace. All statement in the declaration and executable part ends with semicolon (;).

The sub program section: contains all the user defined functions that are called in the main function although
they appear in any order.

Files Used in C Program:


Source Code File: This file includes the source code of the program. The extension for these kind of
files are '.c'. It defines the main and many more functions written in C. main() is the starting point of the
program. It may also contain other source code files.

Header Files: They have an extension '.h'. They contain the C function declarations and macro
definitions that are shared between various source files.

Common standard header files are:


i) string.h – used for handling string functions.
ii) stdlib.h – used for some miscellaneous functions.
iii) stdio.h – used for giving standardized input and output.
iv) math.h – used for mathematical functions.

Object Files: They are the files that are generated by the compiler as the source code file is processed. These
files generally contain the binary code of the function definitions. The object file is used by the linker for
producing an executable file for combining the object files together. It has a '.o' extension.

Executable file: This file is generated by the linker. Various object files are linked by the linker for producing a
binary file which will be executed directly. They have an '.exe' extension.

Compiling and Executing C programs:

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

C is a compiled language. So once a C program is written, you must run it through a C compiler that can create
an executable file to be run by the computer. While the C program is human-readable, the executable file, on
the other hand, is a machine-readable file available in an executable form.

The programming process starts with creating a source file that consists of the statements of the program
written in C language. This source file is processed by a special program called compiler.

Compiler translates the source code into an object file. The code contains the machine instructions for the CPU,
and calls to the operating system API.

However, even object file is executable file. Therefore, the object file is processed with another special program
called as linker. The output of the linker is executable or runnable file.

The Basic ‘C’ Characters – :


A C character set defines the valid characters that can be used in a source program.

The basic C character set are:

1. Letters: Uppercase: A,B,C,….,Z and Lowercase: a,b,c,…..,z

2. Digits: 0,1,2,…..,9

3. Special characters: ! , . # $ ( ) } { etc

4. White spaces: Blank space, Horizontal tab space (\t), carriage return, new line character (\n), form feed
character.
Information Science and Engineering, JIT
Principles of Programming Using C BPOPS203

C – Tokens:
In C program the smallest logically meaning full individual units are known as c tokens. These are also called
as the basic building blocks of C program which cannot be further broken into subparts. C has 6 Different types
of tokens. C programs are written using these tokens and syntax of the language.

i. Keywords
ii. Identifiers
iii. Constants
iv. Strings
v. Operators
vi. Special symbols

1. Keywords: These are predefined words in C compiler which are ment for specific purpose. These words are
also called as reserved words. These words cannot be used as variable names.

These words are usually case sensitive and are usually written in lower case letters only. There are 32 keywords
in C.

2. Identifiers: These are the names given to various elements of the C program like variables, functions,
arrays, etc. These are user defined names and consist of sequence letters, digits or underscore.

Rules to define an Identifiers

1. The first character of the identifier must always be a letter or an underscore followed by any number of
letters digits or underscore.

2. Keywords cannot be used as identifiers or variables.

3. An Identifier or a variable should not contain two consecutive underscores

4. Whitespaces and special symbols cannot be used to name the identifiers.

5. Identifiers are case sensitive (A same variable name declared in uppercase letters and lower case letters are
two different variables in C program).

Examples:
food_court = valid identifier
$num = Invalid identifier ($ is a special symbol)

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

3. Constants: These are the fixed values assigned to the variables which cannot be cannot be changed or
modified in the program. Constants are broadly classified as

Numeric Constants:
Integer Constant: These contain digits or whole numbers without decimal point which can be either
positive or negative.
(i) Decimal: It is an integer constant consisting of numbers from 0-9. It can be preceded by + or –
(ii) Octal: It is an integer constant consisting of numbers from 0-7. It is preceded by o
(iii) Hexadecimal: It is an integer constant consisting of numbers from 0-9, A-F (A=10, B=11, C=12,
D=13, E=14, F=15). It is preceded by 0x

Real Constant: These contain an decimal point or an exponent or both. It can be either positive or
negative or both.
Example: 21.5, 3.142, 6.6260X10-34 , 2.15X102 → 2.15e2

Character Constants:
(i) Single Character Constant: can be single character enclosed within single quotes or a ‘\’
(backslash) followed by any character. ‘\’ is called escape character as it alters the meaning of character
following it. Following are the complete list of escape sequence.

(ii) String Constant: String constants also termed as string literal are sequences of characters
enclosed in double quotes. The character may be letters, numbers, special characters and blank space. a
String literal always ends with a Null character (‘\0’)
Example:

M I T E ‘\0’

Qualified Constant/ Memory Constant: These are created by using “const” qualifier. Const means

that something can only be read but not modified.

Syntax: const datatype variable_name = value;

Ex:

const int a = 10;

const float pi = 3.14

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

Symbolic Constants/ Defined Constant: These are created with the help of define

preprocessor directive.

Ex: #define PI 3.142

During processing the PI in the program will be replaced with 3.142. The name of constant is written in
uppercase just to differentiate from the variables

Data Types: These are the keywords that are used to assign the type of a variable based on the type of data
stored in it. Data types are used to

❖ Identify the type of variable when it is used


❖ Identify the type of return value of the function
❖ Identify the type of parameter expected by the function

There are 3 types:

• Primary/ Built-in/ Fundamental data type - int, float, double, char, void
• Derived data type - array, structure
• User defines data type - typedef

(i) Integer data type: It is used to store whole numbers and its range depends on the word length defined for a
computer. It usually occupies 2 bytes of memory, for signed integers the value ranges from -2n-1 to +2n-1-1 and
for unsigned integers the value ranges from 0 to 2n-1. Keyword int is used to declare variables of integer data
type.

(ii) Floating point data type: It is used to store decimal numbers that have single precision floating point
value. It provides 6 digits after the decimal point and occupies 4 bytes of memory. Keyword float is used to
declare variables of floating point data type.

(iii) Double data type: These are used to store real numbers that have double precision floating point value. It
provides 16 digits after the decimal point. this data type is used when performing complex calculations to get
accurate results. It occupies 8 bytes of memory. Keyword double is used to store the variables of double data
type.

(iv) Char data type: This data type basically stores character type of data. the character data can be an
Alphabet [a to z or A to Z] , digits [0 to 9] and all special characters or symbols[@,$,&,#,...]which is enclosed
with in single quotes. It occupies one byte of memory. Keyword char is used to declare variables of character
data type.

v) Void data type: It does not store any value hence we cannot store any operation on the variable declared as
void. It has no range. Keyword void is used to specify non return data type.

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

Data type Modifiers: Built in data types except void data type can easily be modified by using data type
modifier. There are mainly 4 data type modifiers:
(i) Signed (ii) Unsigned (iii) Long (iv) Short

(i) Signed: it indicates that the variable is capable of storing the negative numbers. The values will be in this
range. -2n-1 to +2n-1-1. Where, n is the size of the particular data type in bits. In declaration we have to use
signed keyword. Example: signed int a;

(ii) Unsigned: it indicates that the variable is capable of storing only positive numbers The values will be in
this range. 0 to 2n-1. Where, n is the size of the particular data type in bits. In declaration we have to use
unsigned keyword. Example: unsigned int a;

(iii) Long: It is used to increase the storage capacity of the variable. long keyword can be used as shown long
int a; //long int occupies 4 bytes of memory.
(iv) Short: It is used to decrease the storage capacity of the variable (capacity is reduced to half). short keyword
can be used as shown short int a; //short int occupies 1 bytes of memory.

Variables:
A variable is a name given to memory location whose value changes during execution.

Declaration:

Syntax: datatype variable_list;

Where,

datatype → Any built in data type

variable_list → Identifiers that specifies variable name.

Initialization:

Syntax: datatype variable_name = value;

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

Where,

datatype →Any built in data type

variable_name → Identifier that specifies variable name.

value → The data which will be stored in variable name.

Example: int a = 10;

Where,

int is a data type

a is a variable name

10 is a value

Information Science and Engineering, JIT


Principles of Programming Using C BPOPS203

Information Science and Engineering, JIT

You might also like