Intro C Programming
Intro C Programming
Objectives:
To enable the students to know about the fundamentals of computer types of
software and operating system.
To learn about of the programming language.
To enable the students to learn the C programs using Arrays, Strings,
Functions, Structures, Pointers and files.
UNIT III: Decision Making and Branching: Introduction – If, If….Else, nesting of
If …Else statements- Else If ladder – The Switch statement, The?: Operator –
The Go to Statement. Decision Making and Looping: Introduction- the While
statement- the do statement – the for statement-jumps in loops. Arrays - Character
Arrays and Strings.
TEXT BOOK
1. E Balagurusamy,” Computing Fundamentals & C Programming” - TataMcGraw-
Hill, Second Reprint 2008, ISBN 978-0-07-066909-3.
REFERENCE BOOK:
1. Ashok N Kamthane: Programming with ANSI and Turbo C, Pearson Edition Publ,
2002.
2. Henry Mullish&HuubertL.Cooper: The Spirit of C, Jaico Pub. House, 1996.
TEXT BOOK
1. E Balagurusamy,” Computing Fundamentals & C Programming” - TataMcGraw-
Hill, Second Reprint 2008, ISBN 978-0-07-066909-3.
Prepared by P.Sundari.
History of Computers
The computer was born not for entertainment or email but out of a need to solve a
serious number-crunching crisis. By 1880, the U.S. population had grown so large
that it took more than seven years to tabulate the U.S. Census results. The
government sought a faster way to get the job done, giving rise to punch-card based
computers that took up entire rooms.
Today, we carry more computing power on our smartphones than was available in
these early models. The following brief history of computing is a timeline of how
computers evolved from their humble beginnings to the machines of today that surf
the Internet, play games and stream multimedia in addition to crunching numbers.
1801: In France, Joseph Marie Jacquard invents a loom that uses punched wooden
cards to automatically weave fabric designs. Early computers would use similar
punch cards.
1890: Herman Hollerith designs a punch card system to calculate the 1880 census,
accomplishing the task in just three years and saving the government $5 million. He
establishes a company that would ultimately become IBM.
1936: Alan Turing presents the notion of a universal machine, later called the Turing
machine, capable of computing anything that is computable. The central concept of
the modern computer was based on his ideas.
1939: Hewlett-Packard is founded by David Packard and Bill Hewlett in a Palo Alto,
California, garage, according to the Computer History Museum.
1941: Atanasoff and his graduate student, Clifford Berry, design a computer that can
solve 29 equations simultaneously. This marks the first time a computer is able to
store information on its main memory.
1946: Mauchly and Presper leave the University of Pennsylvania and receive
funding from the Census Bureau to build the UNIVAC, the first commercial
computer for business and government applications.
1947: William Shockley, John Bardeen and Walter Brattain of Bell Laboratories
invent the transistor. They discovered how to make an electric switch with solid
materials and no need for a vacuum.
1953: Grace Hopper develops the first computer language, which eventually
becomes known as COBOL. Thomas Johnson Watson Jr., son of IBM CEO Thomas
Johnson Watson Sr., conceives the IBM 701 EDPM to help the United Nations keep
tabs on Korea during the war.
1958: Jack Kilby and Robert Noyce unveil the integrated circuit, known as the
computer chip. Kilby was awarded the Nobel Prize in Physics in 2000 for his work.
1964: Douglas Engelbart shows a prototype of the modern computer, with a mouse
and a graphical user interface (GUI). This marks the evolution of the computer from
a specialized machine for scientists and mathematicians to technology that is more
accessible to the general public.
1969: A group of developers at Bell Labs produce UNIX, an operating system that
addressed compatibility issues. Written in the C programming language, UNIX was
portable across multiple platforms and became the operating system of choice
among mainframes at large companies and government entities. Due to the slow
nature of the system, it never quite gained traction among home PC users.
1970: The newly formed Intel unveils the Intel 1103, the first Dynamic Access
Memory (DRAM) chip.
1971: Alan Shugart leads a team of IBM engineers who invent the "floppy disk,"
allowing data to be shared among computers.
1973: Robert Metcalfe, a member of the research staff for Xerox, develops Ethernet
for connecting multiple computers and other hardware.
1974-1977: A number of personal computers hit the market, including Scelbi &
Mark-8 Altair, IBM 5100, Radio Shack's TRS-80 — affectionately known as the
"Trash 80" — and the Commodore PET.
1975: The January issue of Popular Electronics magazine features the Altair 8080,
described as the "world's first minicomputer kit to rival commercial models." Two
"computer geeks," Paul Allen and Bill Gates, offer to write software for the Altair,
using the new BASIC language. On April 4, after the success of this first endeavor,
the two childhood friends form their own software company, Microsoft.
1976: Steve Jobs and Steve Wozniak start Apple Computers on April Fool's Day and
roll out the Apple I, the first computer with a single-circuit board, according
to Stanford University.
1977: Radio Shack's initial production run of the TRS-80 was just 3,000. It sold like
crazy. For the first time, non-geeks could write programs and make a computer do
what they wished.
1977: Jobs and Wozniak incorporate Apple and show the Apple II at the first West
Coast Computer Faire. It offers color graphics and incorporates an audio cassette
drive for storage.
1981: The first IBM personal computer, code-named "Acorn," is introduced. It uses
Microsoft's MS-DOS operating system. It has an Intel chip, two floppy disks and an
optional color monitor. Sears & Roebuck and Computerland sell the machines,
marking the first time a computer is available through outside distributors. It also
popularizes the term PC.
1983: Apple's Lisa is the first personal computer with a GUI. It also features a drop-
down menu and icons. It flops but eventually evolves into the Macintosh. The
Gavilan SC is the first portable computer with the familiar flip form factor and the
first to be marketed as a "laptop."
1986: Compaq brings the Deskpro 386 to market. Its 32-bit architecture provides as
speed comparable to mainframes.
1993: The Pentium microprocessor advances the use of graphics and music on PCs.
1994: PCs become gaming machines as "Command & Conquer," "Alone in the Dark
2," "Theme Park," "Magic Carpet," "Descent" and "Little Big Adventure" are among
the games to hit the market.
1996: Sergey Brin and Larry Page develop the Google search engine at Stanford
University.
1997: Microsoft invests $150 million in Apple, which was struggling at the time,
ending Apple's court case against Microsoft in which it alleged that Microsoft copied
the "look and feel" of its operating system.
1999: The term Wi-Fi becomes part of the computing language and users begin
connecting to the Internet without wires.
2001: Apple unveils the Mac OS X operating system, which provides protected
memory architecture and pre-emptive multi-tasking, among other benefits. Not to be
outdone, Microsoft rolls out Windows XP, which has a significantly redesigned
GUI.
2003: The first 64-bit processor, AMD's Athlon 64, becomes available to the
consumer market.
2004: Mozilla's Firefox 1.0 challenges Microsoft's Internet Explorer, the dominant
Web browser. Facebook, a social networking site, launches.
2005: YouTube, a video sharing service, is founded. Google acquires Android, a
Linux-based mobile phone operating system.
2006: Apple introduces the MacBook Pro, its first Intel-based, dual-core mobile
computer, as well as an Intel-based iMac. Nintendo's Wii game console hits the
market.
2009: Microsoft launches Windows 7, which offers the ability to pin applications to
the taskbar and advances in touch and handwriting recognition, among other
features.
2010: Apple unveils the iPad, changing the way consumers view media and
jumpstarting the dormant tablet computer segment.
2011: Google releases the Chromebook, a laptop that runs the Google Chrome OS.
2015: Apple releases the Apple Watch. Microsoft releases Windows 10.
2016: The first reprogrammable quantum computer was created. "Until now, there
hasn't been any quantum-computing platform that had the capability to program new
algorithms into their system. They're usually each tailored to attack a particular
algorithm," said study lead author Shantanu Debnath, a quantum physicist and
optical engineer at the University of Maryland, College Park.
2017: The Defense Advanced Research Projects Agency (DARPA) is developing a
new "Molecular Informatics" program that uses molecules as computers. "Chemistry
offers a rich set of properties that we may be able to harness for rapid, scalable
information storage and processing," Anne Fischer, program manager in DARPA's
Defense Sciences Office, said in a statement. "Millions of molecules exist, and each
molecule has a unique three-dimensional atomic structure as well as variables such
as shape, size, or even color. This richness provides a vast design space for exploring
novel and multi-value ways to encode and process data beyond the 0s and 1s of
current logic-based, digital architectures."
Generation of Computers
First Generation
1
The period of first generation: 1946-1959. Vacuum tube based.
Second Generation
2
The period of second generation: 1959-1965. Transistor based.
Third Generation
3
The period of third generation: 1965-1971. Integrated Circuit based.
Fourth Generation
4
The period of fourth generation: 1971-1980. VLSI microprocessor based.
Fifth Generation
5
The period of fifth generation: 1980-onwards. ULSI microprocessor based.
First Generation
The period of first generation was from 1946-1959. The computers of first
generation used vacuum tubes as the basic components for memory and circuitry
for CPU (Central Processing Unit). These tubes, like electric bulbs, produced a lot
of heat and the installations used to fuse frequently. Therefore, they were very
expensive and only large organizations were able to afford it.
In this generation, mainly batch processing operating system was used. Punch cards,
paper tape, and magnetic tape was used as input and output devices. The computers
in this generation used machine code as the programming language.
The main features of the first generation are −
ENIAC
EDVAC
UNIVAC
IBM-701
IBM-650
Second Generation
The period of second generation was from 1959-1965. In this generation, transistors
were used that were cheaper, consumed less power, more compact in size, more
reliable and faster than the first generation machines made of vacuum tubes. In this
generation, magnetic cores were used as the primary memory and magnetic tape
and magnetic disks as secondary storage devices.
In this generation, assembly language and high-level programming languages like
FORTRAN, COBOL were used. The computers used batch processing and
multiprogramming operating system.
The main features of second generation are −
Use of transistors
Reliable in comparison to first generation computers
Smaller size as compared to first generation computers
Generated less heat as compared to first generation computers
Consumed less electricity as compared to first generation computers
Faster than first generation computers
Still very costly
AC required
Supported machine and assembly languages
Some computers of this generation were −
IBM 1620
IBM 7094
CDC 1604
CDC 3600
UNIVAC 1108
Third Generation
The period of third generation was from 1965-1971. The computers of third
generation used Integrated Circuits (ICs) in place of transistors. A single IC has
many transistors, resistors, and capacitors along with the associated circuitry.
The IC was invented by Jack Kilby. This development made computers smaller in
size, reliable, and efficient. In this generation remote processing, time-sharing,
multiprogramming operating system were used. High-level languages (FORTRAN-
II TO IV, COBOL, PASCAL PL/1, BASIC, ALGOL-68 etc.) were used during this
generation.
IC used
More reliable in comparison to previous two generations
Smaller size
Generated less heat
Faster
Lesser maintenance
Costly
AC required
Consumed lesser electricity
Supported high-level language
Some computers of this generation were −
IBM-360 series
Honeywell-6000 series
PDP (Personal Data Processor)
IBM-370/168
TDC-316
Fourth Generation
The period of fourth generation was from 1971-1980. Computers of fourth
generation used Very Large Scale Integrated (VLSI) circuits. VLSI circuits having
about 5000 transistors and other circuit elements with their associated circuits on a
single chip made it possible to have microcomputers of fourth generation.
Fourth generation computers became more powerful, compact, reliable, and
affordable. As a result, it gave rise to Personal Computer (PC) revolution. In this
generation, time sharing, real time networks, distributed operating system were
used. All the high-level languages like C, C++, DBASE etc., were used in this
generation.
DEC 10
STAR 1000
PDP 11
CRAY-1(Super Computer)
CRAY-X-MP(Super Computer)
Fifth Generation
The period of fifth generation is 1980-till date. In the fifth generation, VLSI
technology became ULSI (Ultra Large Scale Integration) technology, resulting in
the production of microprocessor chips having ten million electronic components.
This generation is based on parallel processing hardware and AI (Artificial
Intelligence) software. AI is an emerging branch in computer science, which
interprets the means and method of making computers think like human beings. All
the high-level languages like C and C++, Java, .Net etc., are used in this generation.
AI includes −
Robotics
Neural Networks
Game Playing
Development of expert systems to make decisions in real-life situations
Natural language understanding and generation
The main features of fifth generation are −
ULSI technology
Development of true artificial intelligence
Development of Natural language processing
Advancement in Parallel Processing
Advancement in Superconductor technology
More user-friendly interfaces with multimedia features
Availability of very powerful and compact computers at cheaper rates
Some computer types of this generation are −
Desktop
Laptop
NoteBook
UltraBook
ChromeBook
Classification of Computers
Sr.No. Type Specifications
PC (Personal Computer)
A PC can be defined as a small, relatively inexpensive computer designed for an
individual user. PCs are based on the microprocessor technology that enables
manufacturers to put an entire CPU on one chip. Businesses use personal computers
for word processing, accounting, desktop publishing, and for running spreadsheet
and database management applications. At home, the most popular use for personal
computers is playing games and surfing the Internet.
Although personal computers are designed as single-user systems, these systems are
normally linked together to form a network. In terms of power, nowadays high-end
models of the Macintosh and PC offer the same computing power and graphics
capability as low-end workstations by Sun Microsystems, Hewlett-Packard, and
Dell.
Workstation
The workstation is a computer used for engineering applications (CAD/CAM),
desktop publishing, software development, and other such types of applications
which require a moderate amount of computing power and relatively high-quality
graphics capabilities.
Workstations generally come with a large, high-resolution graphics screen, a large
amount of RAM, inbuilt network support, and a graphical user interface. Most
workstations also have mass storage device such as a disk drive, but a special type
of workstation, called diskless workstations, comes without a disk drive.
Common operating systems for workstations are UNIX and Windows NT. Like PC,
workstations are also single-user computers like PC but are typically linked together
to form a local area network, although they can also be used as stand-alone systems.
Minicomputer
It is a midsize multi-processing system capable of supporting up to 250 users
simultaneously.
Mainframe
The 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 much simultaneous execution of
programs.
Supercomputer
Supercomputers are one of the fastest computers currently available.
Supercomputers are very expensive and are employed for specialized applications
that require an immense amount of mathematical calculations (number-crunching).
For example, weather forecasting, scientific simulations, (animated)graphics, fluid
dynamic calculations, nuclear energy research, electronic design, and analysis of
geological data (e.g. in petrochemical prospecting).
Anatomy Of A Computer
A computer can accept input, process or store data, and produce output according
to a set of instructions which are fed into it. A computer system can be divided into
two components which are responsible for providing the mechanisms to input and
output data, to manipulate and process data, and to electronically control the various
input, output, and their storage. They are known as hardware and software.
The hardware is the tangible parts of the computer. Whereas, the software is the
intangible set of instructions that control the hardware and make it perform specific
tasks. Without software, a computer is effectively useless.
1. Hardware
Hardware is the physical components of a computer that includes all mechanical,
electrical, electronic and magnetic parts attached to it. A computer consists of the
following major hardware components:
Nowadays, a high-speed memory, called cache memory, is embedded with the CPU
chip. This improves the computer performance by minimizing the processor need
to read data from the slow main memory. The CPU’s processing power is measured
in terms of the number of instructions that it can execute per unit time. Every
computer comprises of an internal clock, which emits electronic pulses at a constant
rate. These pulses are used to control and synchronize the pace of operations. Each
pulse is called a clock cycle which resembles a rectangular wave with a rising half
of the signal and a falling half. In other words, a full clock cycle is the amount of
time that elapses between pulses of the oscillating signal. Each instruction takes one
or more clock cycles to execute. The higher the clock speed, the more instructions
are executed in a given period of time. Hertz (Hz) is the basic unit of computer
clock frequency which is equal to one cycle per second. CPU speed has been
improved continuously. It is typically measured in megahertz (MHz) or gigahertz
(GHz). One megahertz is equal to one million cycles per second, while one
gigahertz equals one billion cycles per second. Nowadays, multiple processors are
embedded together on a single integrated-circuit chip, known as multi-core
processor e.g. a dual-core processor has two CPUs and a quad core processor has
four CPUs.
Memory unit
Components such as the input device, output device, and CPU are not sufficient for
the working of a computer. A storage area is needed in a computer to store
instructions and data, either temporarily or permanently, so that subsequent
retrieval of the instructions and data can be possible on demand. Data are stored in
memory as binary digits, called bits. Data of various types, such as numbers,
characters, are encoded as series of bits and stored in consecutive memory locations.
Each memory location comprises of a single byte which is equal to eight bits and
has a unique address so that the contents of the desired memory locations can be
accessed independently by referring to its’ address. A single data item is stored in
one or more consecutive bytes of memory. The address of the first byte is used as
the address of the entire memory location. CPU uses registers exclusively to store
and manipulate data and instructions during the processing. Apart from registers,
there are mainly two types of memory that are used in a computer system. One is
called primary memory and the other secondary memory.
Primary memory Primary memory is the area where data and programs are stored
while the program is being executed along with the data. This memory space, also
known as main memory, forms the working area of the program. This memory is
accessed directly by the processor. A memory module consists of a large bank of
flip-flops arranged together with data traffic control circuitry such that data can be
stored or read out on or from a set of flip-flops. A flip-flop can store a binary digit.
These flip-flops are grouped to form a unit memory of fixed length and each of
which is identified by a sequence number known as a memory address. These type
are called Random Access Memory, or RAM, where any location can be accessed
directly, and its stored contents get destroyed the moment power to this module is
switched off. Hence, these are volatile in nature. Primary memory devices are
expensive. They are limited in size, consume very low power, and are faster as
compared to secondary memory devices. There is another kind of primary memory
increasingly being used in modern computers. It is called cache
memory (pronounced as “cash”). It is a type of high speed memory that allows the
processor to access data more rapidly than from memory located elsewhere on the
system. It stores or caches some of the contents of the main memory that is currently
in use by the processor. It takes a fraction of the time, compared to main memory,
to access cache memory. The management of data stored in the cache memory
ensures that for 20 per cent of the total time, during which the cache is searched,
the data needed is found to be stored in cache. As a result the performance of the
computer improves in terms of speed of processing.
Secondary memory Secondary memory provides large, non-volatile, and
inexpensive storage for programs and data. However, the access time in secondary
memory is much larger than in primary memory. Secondary storage permits the
storage of computer instructions and data for long periods of time. Moreover,
secondary memory, which is also known as auxiliary memory, stores a huge number
of data bytes at a lesser cost than primary memory devices.
Note:
Memory operations
There are some operations common to both primary and secondary memory
devices. These are as follows.
Read During this operation, data is retrieved from memory.
Write In this operation, data is stored in the memory. Using read and write
operations, many other memoryrelated functions such as copy and delete are carried
out.
Unit of memory The memory’s interface circuit is designed to logically access a
byte or a multiple of a byte of data from the memory during each access. The
smallest block of memory is considered to be a byte, which comprises eight bits.
The total memory space is measured in terms of bytes. Thus, the unit of memory is
a byte. The capacity of memory is the maximum amount of information it is capable
of storing. Since the unit of memory is a byte, the memory’s capacity is expressed
in number of bytes. Some units used to express the memory capacity are as follows:
The size of the register is one of the important considerations in determining the
processing capabilities of the CPU. Word size refers to the number of bits that a
CPU can manipulate at one time. Word size is based on the size of registers in the
ALU and the capacity of circuits that lead to those registers. A processor with a 32-
bit word size, for example, has 32- bit registers, processes 32 bits at a time, and is
referred to as a 32-bit processor. Processor’s word size is a factor that leads to
increased computer performance. Today’s personal computers typically contain 32-
bit or 64-bit processors.
Memory hierarchy (Memory management)
The various types of memory used in a computer system differ in speed, cost, size,
and volatility (permanence of storage). They can be organized in a hierarchy. The
memory hierarchy in the computer system is depicted as:
Registers
Cache
Main Memory
Secondary Memory
It shows that on moving down the hierarchy, the cost per bit of storage decreases
but access times increases (i.e., devices are slow). In other words, from top to
bottom, the speed decreases while the capacity increases and the prices become
much lower. Of the various memories specified in the hierarchy, those above the
secondary memory are volatile and the rest are non-volatile. While designing a
computer system, there must always be a balance on all of the above factors, namely
speed, cost, volatility, etc. at each level in the hierarchy. The devices in a computer
system other than the CPU and main memory are called peripherals. Popular
peripheral devices include printers, digital cameras, scanners, joysticks, and
speakers.
Interface unit
The interface unit interconnects the CPU with memory and also with the various
input/output (I/O) devices. The instructions and data move between the CPU and
other hardware components through interface unit. It is a set of parallel wires or
lines which connects all the internal computer components to the CPU and main
memory. Depending on the type of data transmitted, a bus can be classified into the
following three types:
Data bus The bus used to carry actual data.
Address bus memory or Input/output device Addresses travel via the address bus.
Control bus This bus carries control information between the CPU and other
devices within the computer. The control information entails signals that report the
status of various devices, or ask devices to take specific actions
Motherboard
All the components in the computer system are mounted and connected
together by an electronic circuit board called motherboard or main board. To
make all these things work together the motherboard provides some kind of
physical connection among them.
Types of Software
Software
Software provides the instructions that tell the hardware exactly what is to be
performed and in what order. This set of instructions is sequenced and organized in
a computer program. Therefore, a program is a series of instructions which is
intended to direct a computer to perform certain functions and is executed by the
processor. In a broader sense, software can be described as a set of related programs.
But software is more than a collection of programs. It refers to a set of computer
programs, which provide desired functions and performance, the data which the
programs use, data structures that facilitate the programs to efficiently manipulate
data and documents that describe the operation and use of the programs. A
comparison between computer program and software is listed below (Table below).
Table Comparison between computer program and software
Computer Program Software
Programs are developed by individuals. A single A large number of developed are
developer is involved. involved.
Extremely large in size and has
Small in size and have limited functionality.
enormous functionality.
For a software product, user
interface must be carefully designed
The user interface may not be very important,
and implemented because
because the programmer is the sole user.
developers of that products and users
of that product are totlly different.
Nowadays, most of the software must be installed prior to their use. Installation
involves copying several files to computer memory or requires a series of steps and
configurations depending on the operating system and the software itself so that it
can be run or executed when required. Software is generally categorized as system
software or application software or utility software.
System software
System software is designed to facilitate and coordinate the use of the computer by
making hardware operational. It interacts with the computer system at low level.
Examples of such software include language translator, operating system, loader,
linker, etc. However, the most important system software is the operating
system which is a set of programs designed to control the input and output
operations of the computer, provide communication interface to the user, and
manage the resources of the computer system, such as memory, processor,
input/output devices etc. and schedule their operations with minimum manual
intervention. Other programs (system and application) rely on facilities provided by
the operating system to gain access to computer system resources. The loader is the
system software which copies a executable program from secondary storage device
into main memory and prepares this program for execution and initializes the
execution. Hardware devices, other than the CPU and main memory, have to be
registered with the operating system by providing a software, known as device
driver, for communication between the device and other parts of the computer. This
type of system software is used by printers, monitors, graphics cards, sound cards,
network cards, modems, storage devices, mouse, scanners, etc. Once installed, a
device driver automatically responds when it is needed or may run in the
background. Modern operating system recognizes almost all connected hardware
devices and immediately begins the installation process. Such a device, for which
the operating system automatically starts the installation process, is called a plug
and- play device. However, there are few hardware devices for which the user has
to manually initiate the installation process.
Application software
Application software is designed to perform specific usages of the users. Microsoft
Word, Microsoft Excel, Microsoft Power Point, Microsoft Access, Page Maker,
Coral Draw, Photoshop, Tally, AutoCAD, Acrobat, WinAmp, Micro Media Flash,
iLeap, Xing MP3 Player etc. are some of the examples of application software.
There are two categories of application software, custom software and pre-written
software packages. Software that is developed for a specific user or organization in
accordance with the user’s needs is known as custom software. A pre-written
software package is bought off the shelf and has predefined generic specifications
that may or may not cater to any specific user’s requirements. The most important
categories of software packages available are as follows:
Database management software, e.g. Oracle, DB2, Microsoft SQL server, etc.
Spreadsheet software, e.g. Microsoft Excel.
Word processing, e.g. Microsoft Word, Corel Word perfect and desktop
publishing (DTP), e.g. Page maker.
Graphics software, e.g. Corel Draw.
Statistical, e.g. SPSS and operation research software, e.g. Tora.
Operating System
Definition
An operating system is a program that acts as an interface between the user and the
computer hardware and controls the execution of all kinds of programs.
Memory Management
Processor Management
Device Management
File Management
Security
Control over system performance
Job accounting
Error detecting aids
Coordination between other software and users
Programming Languages
A programming language is a set of commands, instructions, and other syntax use
to create a software program. Languages that programmers use to write code are
called "high-level languages." This code can be compiled into a "low-level
language," which is recognized directly by the computer hardware.
High-level languages are designed to be easy to read and understand. This allows
programmers to write source code in a natural fashion, using logical words and
symbols. For example, reserved words like function, while, if, and else are used in
most major programming languages. Symbols like <, >, ==, and != are common
operators. Many high-level languages are similar enough that programmers can
easily understand source code written in multiple languages.
Examples of high-level languages include C++, Java, Perl, and PHP. Languages like
C++ and Java are called "compiled languages" since the source code must first
be compiled in order to run. Languages like Perl and PHP are called "interpreted
languages" since the source code can be run through an interpreter without being
compiled. Generally, compiled languages are used to create software applications,
while interpreted languages are used for running scripts, such as those used to
generate content for dynamic websites.
Low-level languages include assembly and machine languages. An assembly
language contains a list of basic instructions and is much more difficult to read than
a high-level language. In rare cases, a programmer may decide to code a basic
program in an assembly language to ensure it operates as efficiently as possible. An
assembler can be used to translate the assembly code into machine code. The
machine code, or machine language, contains a series of binary codes that are
understood directly by a computer's CPU. Needless to say, machine language is not
designed to be human readable.
Translator Programs
A computer, at heart, is really dumb. It can only really know about a few things...
numbers, characters, booleans, and lists (called arrays) of these items. (See Data
Types). Everything else must be "approximated" by combinations of these data
types.
A good programmer will "encode" all the "facts" necessary to represent a problem
in variables (See Variables). Further, there are "good ways" and "bad ways" to
encode information. Good ways allow the computer to easily "compute" new
information.
Algorithm
The core of what good programmers do is being able to define the steps necessary
to accomplish a goal. Unfortunately, a computer, only knows a very restricted and
limited set of possible steps. For example a computer can add two numbers. But if
you want to find the average of two numbers, this is beyond the basic capabilities of
a computer. To find the average, you must:
1. First: Add the two numbers and save this result in a variable
2. Then: Divide this new number the number two, and save this result in a
variable.
3. Finally: provide this number to the rest of the program (or print it for the user).