0% found this document useful (0 votes)
48 views28 pages

Unit 1 PPS

The document provides an overview of computer fundamentals, including the definition, characteristics, and types of computers. It explains the components of a computer system, such as input and output units, storage units, and the central processing unit (CPU). Additionally, it discusses primary and secondary storage, as well as hardware and software distinctions.

Uploaded by

myash4427
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)
48 views28 pages

Unit 1 PPS

The document provides an overview of computer fundamentals, including the definition, characteristics, and types of computers. It explains the components of a computer system, such as input and output units, storage units, and the central processing unit (CPU). Additionally, it discusses primary and secondary storage, as well as hardware and software distinctions.

Uploaded by

myash4427
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

C Programming – UNIT - I

Computer:

1. Charles Babbage is called the "Grand Father" of the computer.


2. The word “computer” comes from the word “compute” which means to calculate. So a computer is
normally considered to be a calculating device that can perform arithmetic operations.
3. Computer cannot do anything without a Program.
4. Computer is an advanced electronic device that takes raw data as input from the user and
processes these data under the control of set of instructions (called program) and gives the result
(output) and saves output for the future use. It can process both numerical and non-numerical
(arithmetic and logical) calculations. The basic components of a modern digital computer are: Input
Device, Output Device, and Central Processor. A Typical modern computer uses LSI Chips. Four
Functions about computer are:

accepts data Input


processes data Processing
produces output Output
stores results Storage

Full form of Computer

C : Common
O : Operating
M : Machine
P : Particularly
U : Used for
T : Trade
E : Education
R : Research

Characteristics of Computer:

1. Speed: - computer is a very fast machine. It can perform any task in few seconds.
2. Accuracy: - Computers are highly accurate machine and they never make mistakes. Errors can
occur in a
Computer, but these are mainly due to human rather than technological weaknesses.
3. Reliability: - computers can be constructed and programmed in such a manner that they would
always yield
guaranteed results.
4. Power of remembering: - A computer can store and recall any amount of information because of
its secondary storage (a type of detachable memory) capability. It saves the effort of inputs every
time, which is useful for many computations in computer. The facility of the storage of data is on
the temporary basis as well a long term basis.
5. Versatility:- Computer is useful everywhere in different respects such as in business, for personal
use at home, in schools for educational purpose, in scientific and engineering application and so on.
Computer can be used for generic as well as specialized purpose.
6. No feeling: - computers are devoid of emotions. They have no feelings because they are machine.

1
C Programming – UNIT - I

Block diagram of digital computer

Storage Units
The storage units of a digital computer hold data and instructions that have been entered through the
input units before and whilst they are being processed. They preserve the intermediate and final results
before they are sent to the output devices. They also save the data for the later use. The various storage
devices of a computer system are divided into two categories:

1. Primary Storage: Random Access Memory. (RAM)

->This stores and delivers data very fast.


->RAM is generally used to hold the program being currently executed in the computer, the data
being received from the input unit and the intermediate and final results of the program.
->RAM memory is temporary in nature: the data is lost when the computer is switched off.
->In order to store the data permanently, the data has to be transferred to the secondary memory
-> Size of main memory is small. Cost is high.

2. Secondary Storage.

->It stores several programs, documents, data bases etc. The programs that you run on the
computer are first transferred to the primary memory before it is actually run. Whenever the
results are saved, again they get stored in the secondary memory. The secondary memory is
slower and cheaper than the primary memory.
->Speed of this memory is slow. But we can use a vest amount of secondary memory to story long
size data. ->Cost of Secondary memory is low.
->Some of the commonly used secondary memory devices are Hard disk, CD, DVD, etc.

Input units
Digital computers need to receive data and instruction in order to solve any problem so they need to input
data and instructions. Input can be entered from a keyboard, a mouse pointing device, a USB stick and
the various types of photo storage cards used by digital cameras. Input can also be downloaded from the

2
C Programming – UNIT - I

Internet via a communications device.


All input peripheral devices perform the following functions:

● Accept the data and instructions from the outside world.


● Convert it to a form that the computer can understand.
● Supply that converted data to the computer system for further processing.

Output Units
The output units of a computer provide the information and results of an arithmetical computation - or
some other kind of data processing, such as a search - to the outside world. Commonly used output units
are printers and visual display units (VDUs), also known simply as "screens". Output data can also be sent
to USB sticks and other types of data storage cards, such as those used by digital cameras. Output can
also be uploaded to the Internet via a communications device.
All output peripheral devices perform the following functions:

● Accept output data and instructions from the computer.


● Convert it to a form that the outside world can understand.
● Supply that converted data to the outside world.

Functional Units of a Computer System


In order to carry out the operations mentioned in the previous section the computer allocates the
task between its various functional units. The computer system is divided into three separate units
for its operation. They are
1) Arithmetic logical unit
2) Control unit.
3) Central processing unit.

Arithmetic Logical Unit


● After you enter data through the input device it is stored in the primary storage unit. The actual
processing of the data and instruction are performed by Arithmetic Logical Unit.
● The major operations performed by the ALU are addition, subtraction, multiplication, division, logic
and comparison. Data is transferred to ALU from storage unit when required.
● After processing the output is returned back to storage unit for further processing or getting stored.

Control Unit (CU)


● The next component of computer is the Control Unit, which acts like the supervisor seeing that things
are done in proper fashion.
● Control Unit is responsible for coordinating various operations.
● The control unit determines the sequence in which computer programs and instructions are executed.
● Things like processing of programs stored in the main memory, interpretation of the instructions and
issuing of signals for other units of the computer to execute them.
● It also acts as a switch board operator when several users access the computer simultaneously.

Central Processing Unit (CPU)


● The ALU and the CU of a computer system are jointly known as the central processing unit.
● You may call CPU as the brain of any computer system.
● It is just like brain that takes all major decisions, makes all sorts of calculations and directs different
parts of the computer functions by activating and controlling the operations.
● The CPU is like brain performs the following functions:
• It performs all calculations.

3
C Programming – UNIT - I

• It takes all decisions.


• It controls all units of the computer.

TYPES OF COMPUTERS

Computers can be classified based on their principles of operation or on their configuration. By


configuration, we mean the size, speed of doing computation and storage capacity of a computer.

There are three types of computers

● Analog Computers
● Digital Computers
● Hybrid Computers

Analog Computer :

● Analog Computer works on continuous range of values.


● It can perform several mathematical operations simultaneously.
● It generally deals with physical variables such as voltage, pressure, temperature, speed, etc.
● They are used more for business applications, because they perform complex computations.
● They are larger than digital computers, but they can't store as much data.
● The first modern analog computer was a tide-predicting machine, invented by Sir William Thomson
in 1872.

Hybrid Computers :

● Hybrid computers are mainly used for specialized tasks.


● These computers are a combination of both digital and analog computers.
● In it, the digital segments perform process control by conversion of analog signals to digital ones.
● It is mostly used for automatic operations of complicated physical processes and machines.

4
C Programming – UNIT - I

● For example, in hospital’s ICU, analog devices might measure the patients temperature, blood
pressure and other vital signs.

Digital Computer

● Digital computer operates on digital data such as numbers.


● It uses binary number system in which there are only two digits 0 and 1. Each one is called a bit.
● It can give more accurate and faster results.
● It is well suited for solving complex problems in engineering and technology.
● It is used in the field of designing, research and data processing.
● There are four different types of computers when we classify them based on their performance and
capacity. The four types are

● Super Computers
● Mainframe Computers
● Mini Computers
● Micro Computers

Super Computers :

● They are the best in terms of processing capacity and also the most expensive ones.
● These computers can process billions of instructions per second.
● Normally, they will be used for applications which require intensive numerical computations
such as stock analysis, weather forecasting etc.
● Other uses of supercomputers are scientific simulations, (animated) graphics, fluid dynamic
calculations, nuclear energy research, electronic design etc.
● Perhaps the best known super computer manufacturer is Cray Research.
● Some of the "traditional" companies which produce super computers are Cray, IBM and HP.

Mainframe Computers :

● Mainframe computers can also process data at very high speeds vi.e., hundreds of million
instructions per second and they are also quite expensive.
● Most of the mainframe computers have capacities to host multiple operating systems and
operate as a number of virtual machines.
● Large organizations use mainframes for highly critical applications such as bulk data processing
and ERP.
● Normally, they are used in banking, airlines and railways etc for their applications.
● They can substitute for several small servers

Mini Computers :

● Mini computers are lower to mainframe computers in terms of speed and storage capacity.
● They are also less expensive than mainframe computers.

5
C Programming – UNIT - I

● Some of the features of mainframes will not be available in mini computers. Hence, their
performance also will be less than that of mainframes.

Micro Computers :

● A computer with a microprocessor and its central processing unit is known as a microcomputer.
● They do not occupy space as much as mainframes do.
● When supplemented with a keyboard and a mouse, microcomputers can be called personal
computers.
● A monitor, a keyboard and other similar input-output devices, computer memory in the form of
RAM and a power supply unit come packaged in a microcomputer.
● These computers can fit on desks or tables and prove to be the best choice for single-user tasks.
● They are further classified into

⮚ Desktop computers
⮚ Laptop Computers

Primary Storage:

Any storage unit of a computer is ranked according to the following criteria:

1. Access Time: This is the time required to locate and retrieve stored data from the storage unit in
response to a program instruction. A fast access time is preferred.
2. Storage capacity: It is the amount of data that can be stored in the storage unit. A large capacity is
desired.
3. Cost per bit of storage: Main goal is to minimize the cost of per bit storage.

Type of primary Storage:

1. RAM [Link]

1. RAM:
● Stands for Random access Memory.
● It stores temporary data into memory.
● When the power supply is switched off, the information stored inside the RAM is Lost.
● It stores essential data required to run programs, such as information and calculation.
● It is also referred to as read/write memory because information can be read from a RAM
chip and also be written into it.
● There are two type of RAM
1. S-RAM (Static RAM)
● Made by flip-flops , an electronic device ,which stores a bit as a voltage.
● Stores temporary data.
● Costly-cost of per bit storage is high
● High speed

2. D-RAM (Dynamic RAM)


● Made by transistor
● Stores temporary data.
● Low cost – cost of per bit storage is low
● High speed

6
C Programming – UNIT - I

2. ROM:
● Stands for Red only memory
● typically used in computers to permanently hold data
● The information from the memory can only be read and it is not possible to write fresh
information into it
● It is supplied by the computer manufacturer and user can not modify the program
stored inside the ROM.
● When the power supply is switched off, the information stored inside the RAM is Lost.
● Read Only Memory is constructed from "hard-wire logic," in a similar way to the
processor, meaning that it cannot be reprogrammed or changed. This is because it is
designed to perform a specific function, and does not need to be altered.
● Example of ROM is a commercial CD purchased from a store; the manufacturers do not
want you to alter what is stored on the disk.
● Type of ROM

1. Programmable Read only memory (PROM): User can write programs at one
time and read it many times. Once the chip has been programmed the recorded
information cannot be changed.

2. Erasable Programmable Read Only Memory (EPROM): Program can be


read, erase and reprogrammed. This type of ROM can only be reprogrammed
using a special type of ultra-violet light, and therefore is only reprogrammed by
manufacturers.

3. Electronically Erasable Programmable Read Only Memory (EEPROM):


EEPROM is the most flexible type of ROM because it can be reprogrammed using
software.
EEPROM is becoming the standard type of ROM used in consumer
motherboards. EEPROM allows the easy "flashing" of motherboard memory when
problems arise or updates are released.

Cache Memory

● Cache (pronounced cash) memory is extremely fast memory that is built into a computer’s central
processing unit (CPU), or located next to it on a separate chip.
● The CPU uses cache memory to store instructions that are repeatedly required to run programs,
improving overall system speed. As the microprocessor processes data, it looks first in
the cache memory.

Registers

● Register is a special- purpose [Link] uses these registers to handle the process of execution
effectively and efficiently.
● They are a part of the central processing unit but cannot be considered as a part of main memory.
● They can hold only one piece of data at a time.
● Registers receive the information, hold it temporarily and pass it to other as directed by the control
unit.
● The number of registers varies from computer to computer, each one designed to perform a
specific function. Registers have a specific storage capacity normally 14 registers are present in a
microcomputer. The most commonly used registers are:
1. Accumulator: stores the result of the last processing step of the ALU.
2. Instruction register: holds the instruction while it is being executed.
3. Address register: holds the location of the next piece of data.

7
C Programming – UNIT - I

4. Program counter: holds the address of the next instruction to e executed.


5. Input/output register: communicates with the input/output devices.

● All data must be represented in a register before it can be processed


● For example, if two numbers are to be multiplied, both numbers must be in registers, and the
result is also placed in a register. (The register can contain the address of a memory location where
data is stored rather than the actual data itself.)
● The number of registers that a CPU has and the size of each (number of bits) help determine the
power and speed of a CPU. For example a 32-bit CPU is one in which each register is 32 bits wide.
Therefore, each CPU instruction can manipulate 32 bits of data.

Secondary Storage :

● Secondary memory (or secondary storage) is the slowest and cheapest form of memory. It cannot
be processed directly by the CPU. It must first be copied into primary storage (also known
as RAM ).
● Secondary memory devices include magnetic disks like hard drives and floppy disks ; optical
disks such as CDs and CDROMs ; and magnetic tapes, which were the first forms of secondary
memory.

❖ Hardware and Software

● Hardware
The physical component of a computer is called hardware. Thus the input, storage,
processing, and output devices are hardware. Ex:- monitor, keyboard, mouse etc..
● Software
Computer cannot do anything on its own. It must be instructed to do the job. Hence it is
necessary to specify a sequence of instructions that a computer must perform to solve the
problem.
A sequence of instruction given to a computer to perform a particular task is called a
program. And set of programs written for a computer is called software.

Ex: MS office, c, c++, java etc.

8
C Programming – UNIT - I

Type of software:

Computer software is classified into two categories.

1. Application Software
2. System Software

1. Application Software
Application software is a set of one or more programs designed to carry out operations for
specific applications.
Or we can say Applications software includes programs that do real work for users.
For example, word processors, spreadsheets, and database management systems.
2. System Software
System software is a set of one or more programs designed to control the operation of a
computer system.
Systems software includes the operating system and all the utilities that enable the
computer to function. For example Operating System, compiler, assembler, utilities etc

❖ Operating System:

● An Operating System (O.S.) is a set of programs that is used to manage the various resource and
overall operations of a computer installation.
● Its prime objective is to improve the performance and efficiency of a computer system and
increase facility.
● OS is responsible for the smooth and efficient operation of the entire computer system.
● It makes the computer system user friendly.
● It is considered the backbone of a computer, managing both software and hardware resources.
● An O.S. provides an environment for the execution of the program.
● It works as a layer between hardware and application program.

User

Application Program

Operating System

Hardware

Functions of Operating System:

1. Process Management :
2. Memory Management :
3. Input / Output Management:
4. File Management :
5. Network Management :
6. Secondary storage management

9
C Programming – UNIT - I

7. Protection and security management


8. User interface
9. Communication Management
10. Interpretation of command and instructions.

Services of Operating System:

O.s. provides services for the convenience of the programmer, to make the programming task
easier. Some of these services are.
1. Program execution services
2. I/O operation services
3. File System services
4. Communication services
5. Error Detection services
6. Protection services
7. Accounting Services

❖ Classification of Operating System:

1. Single Processing System:

● It has a single processor


● Only a single user can interact and runs a single program at a time.
● However the CPU is not utilized to its full potential, because it sits idle for most of the time.
● Ex:-> MS DOS.

2. Multiprogramming Operating System-

● Multiprogramming OS allows the execution of two or more different and independent


programs by the same computer.
● It is used to increase the system utilization and efficiency.

● It reduces the CPU ideal time.

3. Multiprocessing Operating System–

● Multiprocessing OS refers to a computer system’s ability to support and utilizing more than
one computer processor at a time.
● Multiprocessing is used to describe interconnected computers with two or more independent
CPUs that have the ability to simultaneously execute several programs.

● A multiprocessing operating system allows a program to run on more than one central
processing unit (CPU) at a time

● Ex: Linux , Windows 2000

4. Multitasking Operating System–

10
C Programming – UNIT - I

● An operating system that is capable of allowing multiple software processes to run at the
same time.
● Multitasking is the ability to execute more than one task at the same time.
● In Multitasking only one CPU is involved, but it switches from one program to another so
quickly that it gives the appearance of executing all the programs at the same time.
● Ex: Linux , Windows 2000

5. Multithreading Operating System–

● Multithreading Operating systems allows different parts of a single program to run


concurrently.
● The ability of an OS to execute different parts of program, called threads, simultaneously
without interfering with each other.
● Ex: Linux , Windows 2000

6. Real-Time Operating System-

● There are many applications that require an immediate response from the computer.
● Real time means immediate response from the computer.
● Real-time operating systems are designed to allow computers to process and respond to
input immediately.
● Usually, general-purpose operating systems, such as disk operating system (DOS), are not
considered real time, as they may require seconds or minutes to respond to input.
● Real-time operating systems are typically used when computers must react to the
consistent input of information without delay.
● Used in stock market quotation, searching a criminal data file for a possible suspect may all
be actions that need to be done without delay.

7. Distributed System:
● A recent trend in computer system is to distribute computation among several processors.
In contrast to tightly coupled system the processors do not share memory or a clock.
Instead each processor has its own memory and clock.
● The processors communicate with one another through various communication lines such as
high speed buses or telephone lines.
● These systems are usually referred to as distributed system or loosely coupled system.
● The processors in a distributed system may vary in size and function.
● They may include small micro processors, work stations, mini computers and large general
purpose computer systems.
● These processors are referred to by a number of different names, such as sites, nodes,
computers, and so on depending on the context in which they mentioned.
● There are variety of reasons for building distributed system, the major ones being:
o Resource Sharing.
o Computation Speedup.
o Reliability and
o Communication.

❖ Flow Chart:

• A flow chart is a graphical or symbolic representation of a process.


• Each step in the process is represented by a different symbol and contains a short
description of the process step.
• The flow chart symbols are linked together with arrows showing the process flow direction.
• In the case of complicated problems it is desirable to draw a flow chart. This process of
showing diagrammatically the method of solution is referred to as flow chart. A flow chart
indicated the direction of flow of a process, relevant operation and computations, points of
decision and other information which is part of the solution

11
C Programming – UNIT - I

• Different flow chart symbols have different meanings. The most common flow chart symbols
are:

• Terminator: An oval flow chart shape indicating the start or end of the process.

• Process: A rectangular flow chart shape indicating a normal process flow step.

• Decision: A diamond flow chart shape indication a branch in the process flow.

• Connector: A small, labeled, circular flow chart shape used to indicate a jump in the process
flow. (Shown as the circle with the letter “A”, below.)

• Data: A parallelogram that indicates data input or output (I/O) for a process.

• Document: Used to indicate a document or report (see image in sample flow chart below).

❖ Algorithm:

● Algorithm may be formally defined as a sequence of instructions designed in such a way that if the
instructions are executed in the specified sequence, the desired result will be obtained.
● An algorithm is a list of steps for solving a problem.
● It is a sequence of finite instructions, used for calculation and data processing.
● It takes some value or set of values as input and produces some values as output.
● It specifies how to compute the results for any given set of arguments.

Characteristics of an algorithm

1. Input: - valid inputs are clearly specified


2. Output: - can be proved to produce the correct output given a valid input
3. Definiteness: - Strictly and unambiguously(clearly) specified
4. Effectiveness: - steps are sufficiently simple and basic.
5. Finiteness: - terminates after a finite number of steps

❖ Header Files

● These are the files that are included at the top of any program.
● If we use any function inside a program, then the header file containing declaration or definition of
that function. Like printf() is defined in stdio.h. So, we must include it (by #include in order to use
printf ()).
● You request the use of a header file in your program by including it, with the C preprocessing
directive `#include'.
● The header file is included (copy/pasted) during the preprocessing stage and is compiled as part of
the program being written during compilation phase.

12
C Programming – UNIT - I

Including a header file produces the same results as copying the header file into each source file that
needs it. Such copying would be time-consuming and error-prone. With a header file, the related
declarations appear in only one place. If they need to be changed, they can be changed in one place, and
programs that include the header file will automatically use the new version when next recompiled. The
header file eliminates the labor of finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

Library Files

● These are the files which contains the definition (how it will work) of the functions which you are
using in your program.
● Compiler uses these files in order to define the functions which have been used in the program and
had been declared inside the header file. Like, printf() has its complete definition ,like how it will
work etc. in an I/O library
● The compiler uses that library to get the machine code for the functions like printf().

Difference between header files and library files:

1. Header files are TEXT files while library files are BINARY. This means, we can read and modify the
header file but not the library!
2. Header file is in C language while the library is in machine language!
3. Header file has to be included by the programmer while the compiler automatically relates the library
file(s) with the program!

❖ Basic Structure of C Programming.

Any C program is consists of 6 main sections.

13
C Programming – UNIT - I

1. Documentation Section : This section consists of comment lines which include the name of
programmer, the author and other details like time and date of writing the program.
Documentation section helps anyone to get an overview of the program.

2. Link Section : The link section consists of the header files of the functions that are used in the
program. It provides instructions to the compiler to link functions from the system library.

3. Definition Section : All the symbolic constants are written in definition section. Macros are
known as symbolic constants.

4. Global Declaration Section : The global variables that can be used anywhere in the program
are declared in global declaration section. This section also declares the user defined functions.

5. main() Function Section : It is necessary to have one main () function section in every C
program. This section contains two parts, declaration and executable part. The declaration part
declares all the variables that are used in executable part. These two parts must be written in
between the opening and closing braces { }. Each statement in the declaration and executable
part must end with a semicolon (;). The execution of program starts at opening braces and
ends at closing braces.

6. Subprogram Section :The subprogram section contains all the user defined functions that are
used to perform a specific task. These user defined functions are called in the main() function.

14
C Programming – UNIT - I

❖ Syntax and Logical Error in C

● Errors are the problems or the faults that occur in the program, which makes the behavior of
the program abnormal
● These errors are detected either during the time of compilation or execution
● Thus the errors should be removed before compiling and executing.
● Programming errors are also known as the bugs or faults, and the process of removing these
bugs is known as debugging.

Syntax errors:

● Syntax errors are also known as the compilation errors as they occurred at the compilation
time
● Syntax errors occur when violate the rules of writing C syntax
● Syntax errors must be fixed before the compilation of the code.
● Most frequent syntax errors are:
• Missing Parenthesis (})
• Missing semicolon

● Example
#include<stdio.h>
void main()
{
int x = 10 // semicolon missed
printf("%d", x);
}

Logical Errors:

● The errors which provide incorrect output but appear to be error free are called logical errors.
● These are one of the most common errors done by beginners of programming.
● These errors solely depend on the logical thinking of the programmer and are easy to detect
if we follow the line of execution step by step.

15
C Programming – UNIT - I

● Example: program of addition of two numbers

#include<stdio.h>
void main()
{
int x = 10,y=20,z;
z=x*y; //by mistake using * in place of +(Logical error)
printf("%d", x);
}

❖ Object Code and Executable Code

Object Code-

The computer does not understand the source program or the source code. Therefore, the compiler
converts the source program into an object program. It contains the instructions for the machine to
perform. These instructions are in the form of binary digits. The machine understands this object
code. Therefore, the computer can execute this code. Generally, the object code is specific to the
system architecture. Extension of object code is .obj.

Executable code-

Executable code is a file or a program that indicates tasks according to encoded instructions.
Executable code (also called the Binary) is the output of a linker after it processes the object code.
A machine code file can be immediately executable (i.e., runnable as a program), or it might require
linking with other object code files (e.g. libraries) to produce a complete executable program.
Extension of executable code is .exe.
Sometimes possible to consider a bytecode or scripting language instructions as an
executable code.

❖ components of C language

There is five main components of C language:-


1. Character set
2. Datatype
3. Identifiers / Variables
4. Constants
5. Keyword

1. The character set:

● Any alphabet, digit or special symbol, used to represent information is denoted by character.
● The characters in C are grouped into four categories:-

16
C Programming – UNIT - I

i) Letters- A...Z and a...z


ii) Digits- 0, 1, 2 ...9
iii) Special Symbol - ~ ` ! @ # $ % ^ & * () . < > ? / " : ; { }[ ] etc.
iv) White Space, blank space, Carriage return, form feed, newline, horizontal tab.
Some of the special characters are listed below:
+-*~%/&(){}[]?"<>!;:

● Most versions of the language also allow certain other characters, such as @ and $,
to be included within strings and comments.
● C uses certain combinations of these characters, such as \b,\n and \t, to represent
special conditions such as backspace, new line, and horizontal tab, respectively.
● These character combinations are known as escape sequences.

2. The data types:

● A data type, in programming, is a classification that specifies which type of value a variable
has and what type of mathematical, relational or logical operations can be applied to it
● We can use several basic types of data values such as character, integer, float, double etc.

3. Variable / identifier :

● Variable or identifier is a name of a memory area which is used to store the value
● A variable is an entity whose value can change during program execution.
● Variable names are names given to locations in memory.
● These locations can contain integer, real or character constants.

4. Constants:

● A constant is a fix value that doesn't change while program execution.


● There are basically 2 types of constants
i) Primary constants:- Integer constants, Real constants, Character constraints.
ii) Secondary constants:- Array, Structure, Union, Pointer, etc.
Character constants are enclosed between single quotes. e.g. 'a' & '%' etc.

5. Keyword :

● Keywords are the words whose meaning has already been explained to the C compiler
● The keywords cannot be used as variable names because if we do so we are trying to assign
a new meaning to the keyword, which is not allowed by the computer.
● There are 32 keywords available in C.
● Rules to be followed for all programs written in C:
o All keywords are in lower case.
o C is case sensitive so int is different from Int.

17
C Programming – UNIT - I

o The keywords cannot be used as variable names because if we do so we are trying to


assign a new meaning to the keyword, which is not allowed by the computer.
● List of C programming keywords.

What is Language :

• Language is medium of communication.


• If two persons want to communicate with each other , they have to use a common language.
• Like Hindi, English, Punjabi etc.

What is Programming Language :

• In the same way when a user wants to communicate with a computer ,the language that he/she uses for this
purpose is known as programming language .
• Like BASIC, COBOL, C, C++, JAVA ……
• At the same time we know that computer understands only one language that is MACHINE LANGUAGE which is
in 0 & 1 format.
• It is very difficult for us to learn this language.
• For Example two persons belonging to two different countries , want to communicate then there may be a
problem of common communication medium.
• To solve this problem there is a requirement of translator.

Types of programming Language:

Machine Language:

• It is in 0 and 1 format
• No need to translate.
• Programs are less understandable
• Difficult to write large programs
• Debugging is most difficult.
• Programs are machine dependent

18
C Programming – UNIT - I

• Not portable: portable to machine of the same architecture only

Assembly Language:

• Uses mnemonic for programming (ADD,STORE)


• Need assembler to translate from assembly to machine language
• Programs are more understandable then machine language and less understandable then High level language.
• Difficult to write large programs but easy then machine language
• Debugging is easy then machine language and complex then high level language
• Programs are machine dependent
• Not portable: portable to processor of the same architectures only

High Level Language:

• It uses natural language elements, which is easy to use.


• Need translator(compiler or assembler) to translate from high level language to object code
• Easy to understand
• Easy to write large programs and suitable for software development
• Debugging is easier than others
• Programs are not machine dependent
• Programs are portable

Types of Translator:

1. Assembler
2. Complier
3. Interpreter
Assembler:

• Assembly and machine language are low level language


• The assembly codes are easier to write but system can executes the machine code.
• So we need a translator (Assembler) to translate assembly code to machine code.

Compiler:

• Used to translate high level source code to object code.


• Compiler scans all the lines of source program and list out all syntax errors at a time.
• It takes less time to execute.
• Object produced by compiler gets saved in a file. So file do not need to compile again and again

Interpreter:

• Used to translate source code to object code.

19
C Programming – UNIT - I

• Interpreter scans one line at a time of source program if there is any syntax error , the execution of program
terminates immediately.
• It takes more time to execute.
• Machine code produced by interpreter is not saved in any file . So we need to interpret the file each time(BASIC
is an interpreter based language)

Linker and loader:

linker and loader is part of any translator(compiler and assembler)

Loader:

● Loader is a operating system utility that copies program from a storage device to main memory, where they
can be executed.
● It is a part of O.S. and used to load the program.
● Most loaders are transparent i.e. you can not directly execute them,but the O.S. use them when necessary.

Linker:

● A linker is a program that combines object modules to form an executable program.


● Also called link editor
● It links the object modules with library functions and create executable program.

Generation of Language

First generation - machine language


Second generation - assembly language
Strong points:- what cannot be done in assembly language can just not be done at all with the given hardware.
Drawback:- control flow mechanisms (like if, while , for ) are not directly available. I/O function are not present , the
program is not portable at all and programmer must have the knowledge of hardware
Third generation - was designed precisely to solve the problem of assembly .Languages like (COBOL, FORTRAN
and Pascal providing high label I/O Facilities, hardware independence and so on. But these languages takes
programmer away from hardware and they were not suitable for system label programming (task like writing OS
etc).So there was a need of a language which should have feature of 3-GL with power of assembly. So the language
CPL (Combined Programming Language) was came in picture .but CPL was very bulky and complex language so
we had small derivative of CPL as BCPL (Basic CPL) by Martin Richards. BCPL further adapted by Ken
Thompson to develop another language called B, and then C was developed by Dennis Ritchie based on B.

Introduction of ‘C’:
● C was developed by Dennis Ritchie at AT & T bell laboratory of USA in 1972.

20
C Programming – UNIT - I

BCPL -> Martin Richards


B -> Ken Thompson
C ->Dennis Ritchie

● C is the result of a development process that started with an older language called BCPL. BCPL was developed by
Martin Richards, and it influenced a language called B, which was invented by Ken Thompson. B led to the
development of C in the 1970s.
● It is a case sensitive Language.
● Extension of ‘C’ program file is “.C” .
● It is also called a Middle Level Language.

The C Character Set:


A character denotes any alphabet, digit or special symbol used to represent information. ‘C’ allows several alphabets,
numbers, and special symbols

‘C’ Programming Tokens:


1. Keywords
2. Identifiers
3. Variables
4. Constants
5. Operators
6. Special Symbols

1. ‘C’ KEYWORDS:

● Keywords are the words whose meaning has already been explained to the C compiler
● The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to
the keyword, which is not allowed by the computer.
● There are 32 keywords available in C.
● Rules to be followed for all programs written in C:
o All keywords are in lower case.
o C is case sensitive so int is different from Int.
o The keywords cannot be used as variable names because if we do so we are trying to assign a new
meaning to the keyword, which is not allowed by the computer.
● List of C programming keywords.

21
C Programming – UNIT - I

2. IDENTIFIERS :

● Identifiers refer to the naming of programming elements like variables, functions and arrays.
● These are user-defined names and consist of sequence of letters and digits, with a letter as a first character.
● Both uppercase and lowercase letters are permitted, although lowercase letters are commonly used.
● The underscore character is also permitted in identifiers. It is usually used as a link between two words in
long identifiers.
● Some legal identifier :
arena, s_count
marks40
class_one
● Some illegal identifiers:
o 1stsst
o oh!god
o start….end
● The number of characters in the variable that are recognized differs from compiler to compiler.
● An identifier cannot be the same as a C keyword.

3. VARIABLE :

● Variables are named locations in memory that are used to hold a value that may be modified by the
program.
● Unlike constants that remain unchanged during the execution of a program.
● A variable may take different values at different times during execution.
● The syntax for declaring a variable is –
DataType IdentifierName ;
Example. int num;
long int sum , a;

4. CONSTANT :

22
C Programming – UNIT - I

● Constants are named locations in memory that are used to hold a value that cannot be modified by the
program.
● Constants remain unchanged during the execution of a program.
● const keyword is used to declare constant data.
● The syntax for declaring a constant is –
const DataType IdentifierName ;
Example. const float PI = 3.14f;

● Types of C Constants
C constants can be divided into two major
categories:
o Primary Constants
o Secondary Constants

5. OPERATORS :

• C supports rich set of operators.


• An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.
• Operators are used in programs to manipulate data and variables.
• Types of operators

1. Unary operator(+,-,++,--)

2. Binary operator
a. Arithmetic operators (+,-,*,/,%)
b. Relational operators (<,>,<=,>=,==,!=)
c. Logical operators(&&(logical AND),||(logical OR),!(logical Not))
d. Assignment operators (=)
e. Bitwise operators (~,>>,<<,^,&,|)
• C supports bitwise operators for manipulation of data at bit level.
• Bitwise operators may not be applied to float or double.

23
C Programming – UNIT - I

• Bitwise operators are as follows:


& bitwise AND
| bitwise OR
^ bitwise exclusive OR
<< shift left
>> shift right
~ One’s Complements

f. Special operators (. ,sizeof(),&,->)

3. Ternary operator

• C supports a ternary operator i.e. conditional operator.


• The conditional operator is defined as
“?:”
• The conditional operator works in following format:
Syntax : (condition) ? true statement : false statement ;

for example:
void main()
{
int a=11, b=20;
( a==b) ? printf(“both r Equal”) : printf(“Not Equal”) ;
}

Output: Not Equal

6. SPECIAL OPERATOR :

● ! , @, #, $ , & , * , …..
● These all symbols are called Special Symbols.
● Every symbol has its special meaning in different respect at different place that’s why it is called Special
Symbols.
Data Type:

● C language is rich in its data type.


● Data type tells the type of data, that you are going to store in memory.
● It gives the information to compiler that how much memory ( No. of bytes ) will be stored by the data.

The C language supports a number of data types, all of which are necessary in writing

24
C Programming – UNIT - I

programs. The basic data types of C language are defined by the ANSI standard are listed in diagram.

Type Size Description

char 1byte Used for characters or integer variables.


int 2 or 4 bytes Used for integer values.
float 4 bytes Single precision floating point values
double 8 bytes Double precision floating point values

In addition to these data types, some of them may be used with a modifier that affects
the characteristics of the data object. These modifiers are listed in Table.

Modifier Description

long Forces a type int to be 4 bytes (32 bits) long and forces a type double to be larger than a double
(but the actual size is implementation defined). Cannot be used with short.

short Forces a type int to be 2 bytes (16 bits) long. Cannot be used with long.

unsigned Causes the compiler (and CPU) to treat the number as containing only positive values. Because a
16-bit signed integer can hold values between –32,768 and 32,767, an unsigned integer can hold
values between 0 and 65,535. The unsigned modifier can be used with char, long, and short
(integer) types.

The essence of all the data types that we have learnt so far has been captured in Table.

25
C Programming – UNIT - I

❖ Storage Class:
To fully define a variable we need to mention :
1. Type of variable i.e ( int, char, float )
2. The storage class of a variable
The storage class is associated with a variable which decide what would be the default value of variable, where it would get
stored, what will be the life of variable, and what will be the scope of variable.
Moreover, a variable’s storage class tells us:
● Where the variable would be stored.
● What will be the initial value of the variable, if initial value is not specifically assigned.(i.e. the default initial
value).
● What is the visibility of the variable; i.e. in which functions the value of the variable would be available.
● What is the scope or life of the variable; i.e. how long would the variable exist.

Types of Storage class :


1. Automatic storage class
2. Register storage class
3. Static storage class
4. Extern storage class

1. Automatic storage class : (this is default class)

Keyword : auto
Default value : garbage
Storage : memory
Scope of variable : Local to block
Life of variable : till control remains in the block in which it is declared.
Ex: auto int x;
Ex:

26
C Programming – UNIT - I

#include<stdio.h> //header file


void main() //main function
{
auto int x=10; //variable declaration and initialization
{
auto int x=20;
printf(“%d”,x); //printf() method to print value of x
}
printf(“%d”,x);
}
Output :20 ,10

2. Register storage class :


Keyword : register
Default value : garbage
Storage : registers of CPU
Scope of variable : Local to lock
Life of variable : till control remains in the block in which it is declared.
Ex: register int x;
Ex:

Void main()
{
register int r;
for(r=1;r<=10;r++)
Printf(“%d”,r);
}
Output:1,2,3,4,5,6,7,8,9,10

Note : If any CPU register is not available to store data then ‘c’ compiler automatically convert the storage
class from register to automatic, because number of CPU registers are limited..

3. Static storage class


Keyword : static
Default value : zero
Storage : memory
Scope of variable : local to block
Life of variable : till the program is running, and it persist in various function call
Ex: static int x;

Ex:
void main()
{
static int x;
printf(“%d”,x);
x++;
if(x<=10)
main();

27
C Programming – UNIT - I

}
Output:0,1,2,3,4,5,6,7,8,9,10

4. Extern storage class


Keyword : extern
Default value : zero
Storage : memory
Scope of variable : global from point of declaration onwards
Life of variable : till program execution does not come to an end

28

You might also like