Module 1 POP Notes
Module 1 POP Notes
Module 1: Introduction to C
Computer: A computer in simple terms can be defined as an electronic device that is designed to
accept data, perform the required mathematical and logical operations at high speed and output
the result.
Characteristics of computer:
1. Speed:
Unlike humans, a computer never gets tired of a repetitive task. It can continually work for hours
without creating errors.
5. Versatile:
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.
6. Memory:
similar to humans, computers also have memory .While the internal memory of computers is
very expensive and limited in size the secondary storage is cheaper and of bigger capacity.
7. No IQ:
Although the trend today is to make computers intelligent by including artificial intelligence (AI)
in them, they still do not have any decision-making abilities of their own. That is, their IQ level
is zero. They need guidance to perform various tasks.
8. Economical:
Using computers also reduce man power requirements and leads to an elegant and efficient way
of performing various tasks. Hence, computers save time, energy, and money. When compared
to other systems, computers can do more work in lesser time.
2. Later Harvard University proposed a stored program concept in which h there was a
separate memory to store data and instructions.
Computer generations :
Generation in computer terminology is change in technology a computer is being used. There is
five generation of computers.
This generation computer is used thousands of vacuum tubes for circuitry for CPU
(Central processing unit)
Memory requirement were met by magnetic drums.
Took lot of space consumed enormous amount of power and generated lot of heat and
also was very expensive.
These computers used machine language.
Some computers of this generation were: ENIAC, EDVAC, UNIVAC etc..
Program input was provided by punch cards and outputs were produced on paper.
Transistors were used that were cheaper, consumed less power, more compact in size,
more reliable and faster.
Magnetic cores were used as the primary memory and magnetic tape and magnetic disks
as secondary storage devices.
These computers used assembly language (programmer could specify words and symbols
as instructions instead of 0’s and 1’s).
Some computers of this generation were: IBM 1620, IBM7094.
Used very large scale integrated (VLSI) circuits having about 5000 transistors and other
circuit elements with their associated circuits on a single chip.
With ULS (ultra large scale integration) technology, microprocessor chips having ten
million electronic components were manufactured.
This generation is based on parallel processing hardware and AI.
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 .
Neural networks and experts systems have to be developed.
Classification of computer:
Computers are broadly classified into 4 types based on speed, amount of data that they can hold
and price.
1. Super computer:
The super computer is the fastest, most powerful and most expensive computer.
Supercomputers were first developed in the 1980’s to process large amounts of data and
to solve complex scientific problems.
A single supercomputer can support thousands of users at the same time.
Computers are mainly used for weather forcasting, nuclear energy research, aircraft
design, automotive design, online banking, controlling industrial units, etc.
ii. Intelligent terminals:-Intelligent terminals have their own processor and thus can
perform some processingoperations..They do not have their own storage space.
3. Mini computer:
4. Micro computers:
laptop). PCs today are powered by 3 types of OS – windows (7, 8 or 10), Mac OS X
(Apple) and Linux.
They are used for engineering and scientific applications and for software development.
PCs can be classified into the following categories.
o Desktop
o Laptops
o Workstations
APPLICATIONS OF COMPUTERS
When the first computers were developed, they were used only in the fi elds of mathematics
and science. Today, computers are widely used in fi elds such as engineering, health care,
banking, education, etc.
1) Word processing -Word processing software enables users to read and write documents.
Users can also add images, tables, and graphs for illustrating a concept. The software
automatically corrects spelling mistakes and includes copy–paste features.
2) Internet The Internet is a network of networks that connects computers all over the world. It
gives the user access to an enormous amount of information, much more than available in
any library.
3) Digital video or audio composition Computers make audio or video composition and
editing very simple.
4) Desktop publishing software enables us to create page layouts for entire books.
5) e-Business or electronic business is the process of conducting business via the Internet. This
may include buying and selling of goods and services using computers and the Internet.
6) Business-to-consumer or B2C In this form of electronic commerce, business companies
deploy their websites on the Internet to sell their products and services to the customers.
7) Business-to-business or B2B This type of electronic commerce involves business
transactions performed between business partners.
8) Consumer-to-consumer or C2C This type of electronic commerce enables customers to
carry business transactions among themselves.
9) Electronic banking, also known as cyberbanking or online banking, supports various
banking activities conducted from home, a business, or on the road instead of a physical bank
location.
10) Bioinformatics is the application of computer technology to manage large amount of
biological information. Computers are used to collect, store, analyse, and integrate biological
and genetic information to facilitate gene-based drug discovery and development.
11) Health care- storing records, surgical procedure, better diagnosis and treatment.
12) Geographic Information System and Remote Sensing- A geographic information system
(GIS) is a computer based tool for mapping and analysing earth’s features. Remote sensing is
the science of taking measurements of the earth using sensors on airplanes or satellites.
13) Meteorology – weather forecasting, agriculture, nuclear and maritime meteorology.
14) Legal – computers are used by lawyers.
15) Multimedia and animation
16) Retail business – in stores.
17) Travel and tourism
18) Education
19) Astronomy
20) Industry and engineering
This is the process of entering data instructions into the computer system.
The data and instructions can be entered by using different input devices such as
keyboard, mouse, scanner, trackball, etc...
Note that the computers understand binary language, which consist of only two symbols
(0 and 1), so it is the responsibility of the input devices to convert the input data into
binary codes.
Storage:
Storage is the process of saving data and instructions permanently in the computer so that they
can be used for processing.
1. Primary storage:
Primary storage also known as the main memory is the storage area that is directly
accessible by the CPU at very high speed.
Drawback of main memory is that it is volatile in nature that is as soon as the
computer is switched off, the information stored gets erased.
RAM and ROM are the examples of primary storage
RAM:
ROM:
It stands for read only memory the data stored in these devices are non-volatile
i.e. oncethe data stored in the memory cannot be modified or deleted.
The memory form which will only read but cannot write.
The information is stored permanently.There are 3 types
1. PROM (programmable ROM) :Data cannot be altered
2. EPROM(Erasable Programmable ROM): Possible to erase the information
3. EEPROM (electrically Erasable ROM): non-volatile memory used in computers,
usually integrated in microcontroller
2. Secondary storage:
Also known as auxiliary memory this is just the opposite of primary memory. It
basically overcomes all the drawbacks of the primary storage area.
It is cheaper, non-volatile and used to permanently store data and programs of
those jobsthat are not being currently executed by the CPU.
Processing:
The process of performing operations on the data as per the instructions specified by the
user(programs) is called processing.
Data and instructions are taken from the primary memory and transferred to the arithmetic
and logical unit, which performs all sorts of calculations.
The intermediate results of processing may be stored in the main memory as they be
required again.
When processing completes the final result is then transferred to the main memory
.Hence the data may move from main memory to the ALU multiple times before the
processing is over.
Output:
Output is the processing of giving the result of data processing to the outside world.
The results are given through output devices such as monitor, printer etc...
The output devices therefore convert the results available in binary codes into a human-
readable language before displaying it to the user.
Control:
The control unit is the central nervous system of the entire computer system. It manages and
controls all the components of the computer system. It is the CU that decides the manner in
which instructions will be executed and operations performed
MOTHERBOARD
The motherboard, also known as the mainboard or the parent board is the primary component of
a computer. It is used to connect all the components of the computer. The motherboard is a
printed circuit that has connectors for expansion cards, memory modules, the processor, etc.
Characteristics of a Motherboard
A motherboard can be classifi ed depending on the following characteristics:
• Form factor
• Chipset
• Type of processor socket used
• Input–Output connectors
An input device is used to feed data and instructions into the computer. In the absence of an input
device, a computer would have only been a display device.
Input devices
Track pad
Joystick
OCR
OMR
MICR
Keyboard:
The keyboard is the main input device for computers. Computer keyboards look very
similar to the keyboards of typewriters with some additional keys.
Most keyboards have between 80 and 110 keys.
The layout of a keyboard is known as QWERTY for its first six letters.
Types of keys:
a. Typing keys – includes letters of alphabets.
b. Numeric keys – set of keys arranged like a calculator with numbers and symbols
(+,-,*,/,.,).
c. Function keys – used by applications and OS to input specific commands.
d. Control keys – they are used to handle control of cursor and the screen. Four
arrow keys , Home, End, Insert, Delete, Page up and page Down keys, Ctrl, Esc,
Alt, Pause, PrintScreen , Windows, Start Keys are some of the control keys.
Key board has circuitry called key matrix, which will be completed when the key is pressed.
Pointing devices:
Spoorthi M, Dept of CSE, CEC, Bangalore Page 10
Principles of Programming using C Module 1
Pointing input devices enable the users to easily control the movement of the pointer to
select items on a display screen to select commands menu, to draw graph, etc...
Some examples of pointing devices include mouse, track ball, light pen joystick and
touch pad
a. Mouse:
The mouse is an input device that was invented by Douglas Engelbart in 1963.
It is the key input device used in a graphical user interface
It can be used to handle the pointer easily on the screen to perform various functions such
as opening a program or file.
The mouse has two buttons and a scroll wheel. It can be held in the hand and easily
moved without lifting, along a hard flat surface to move the cursor to the desired
location-up, down, left, right.
Once the mouse is placed at appropriate postion,the user may perform the following
operation:
o Point: Placing the mouse pointer over the word or the object on the screen by
moving the mouse on the desk is termed as pointing.
o Click: pressing either the left or the right button of the mouse is known as
clicking.
o Drag: Pointing to a desired location while pressing the left button.
The most popular Mouse types are:
i. Mechanical mouse:- This type of mouse has a rubber or metal ball at its
bottom and an electronic circuitcontaining sensors.
ii. Optical mouse:- The movement of the mouse is detected using laser technology,
by using optical sensors.
iii. Cordless mouse:- is not connected to the computer. The movement of the
mouse is detected using radio waves or infrared light.
b. Track ball:
A trackball is a pointing device that is used to control the position of the cursor on the
screen. It is usually used in notebook computers, where it is placed on the keyboard.
c. Touchpad:
A touchpad (track pad) is a small, flat, rectangular stationary pointing device with a
sensitive surface of 1.5-2 square inches.
The user has to slide his or her fingertips across the surface of the pad to point to a
specific object on the screen.
The surface translates the motion and position of the users fingers to relative position on
the screen.
There are also button around the edge of the pad that work like mouse buttons.
Touch pad are widely used in laptops and are in built on the laptop keyboard.
Handheld device:
Joystick: A joystick is a cursor control device widely used in computer games and computer aided
design(CAD)/computer aided manufacturing (CAM) applications.
Stylus:- A stylus is a pen-shaped input device used to enter information or write on the
touchscreen of a handheld device.
Touch screen:
A touch screen is a display screen that can identify the occurrence and position of a touch
inside the display region.
The user can touch the screen either by using a finger or a stylus.
The touch screen facilitates the users to interact with what is displayed on the screen in a
straightforward manner, rather than in an indirect way by using a mouse or a touchpad.
Optical devices:
Optical devices also known as data-scanning devices use light as a source of input for
detecting or recognizing different objects such as characters, marks, codes and images.
The optical device converts these objects into digital data and sends it to the computer for
further processing
Barcode reader:
A barcode reader is a handheld input device that ais used to capture and read information
stored in a barcode
It consists of a scanner a decoder and a cable used to connect the reader to a computer.
The function of the barcode reader is to capture and translate the barcode into numerical
and/or alphabets.
It is connected to computer for further processing of the captured information.
Image scanner:
A scanner is a device that captures images, printed text and handwriting from different sources
such as photographic prints, posters and magazines and converts them into digital images for
editing and displaying on computer.
Optical character recognition:
ptical character recognition is the process of converting printed materials into text or word
processing files that can be easily edited and stored.
Optical mark recognition is the process of electrically extracting data from marked fields
such as checkboxes and fill in fields on printed forms.
The optical mark reader is fed with an OMR sheet that has pen or pencil marks is pre-
defined positions to indicate each selected response marks and space and stores the
interpreted data in a computer for storage analysis and reporting
Magnetic ink character reader is used to verify the legitimacy of paper documents
especially bank checks.
It consists of magnetic ink printed characters that can be recognized by high speed
magnetic recognition devices.
Video input devices are used to capture video from the outside world into the computer.
Digital camera and webcam are the popular examples of video input device.
A digital camera is a handheld and easily portable device used to capture images or
videos.
The digital cameras digitalize images or video and store them on a memory card.
Web cameras too capture videos that can be transferred via the internet in real-time.
Web cameras are widely used for video conferencing
Output devices:
Output devices
Monitor: The monitor is an integral part of computer which displays both text and graphics.
The performance is measured in terms of image quality, resolution, energy consumption.
Printer: Printer is an output device that prints any data, report, document, picture, diagrametc.
Printers are classified into:
Printers
Plotters: The plotter can make drawings. It uses one or more automated pens. The
commands are taken from special file called vector graphic files.
Speakers: The speaker is an output device which produces the voice or sound waves.
Projector: The projector is the by-pass device for the monitor where it produces larger
images or pictures
Designing efficient programs
Programming paradigm is a fundamental style of programming the define how the structure
and basic elements of computer program will be built. These paradigms in sequence of their
application can be classified as follows
1. Monolithic program- programs written using monolithic programming languages consist
of global data and sequential code. The Global data can be accessed and modified from
any part of the program. A sequential code is one in which instructions are executed in a
specific order. To change the sequence of execution, jump or goto statements. It will
have just one program module. The size of the program will be large as there is no
concept of subroutine and difficult to debug.
ADD 10
BDB 20 Global data
SUM DB?
MOV AX, A
ADD AX,B
MOV SUM, AX Sequential code with
JMP STOP jump instruction
……….
STOP: EXIT
Global Data
subroutines
Program
Example FORTRAN and cobol are two popular procedural programming language.
Advantages
a) The only goal is to write correct programs.
b) Programs are easier to write compared to Monolithic programming.
Disadvantages
a) No concept of reusability.
b) Requires more time and effort to write programs.
c) Programs are difficult to maintain.
d) Global data are shared and may get altered.
3. Structured programming
It is also referred to as modular programming. It will be used basically in large programs
that require large development team to develop different parts of the same program.
Structure programming employs top down approach in which overall program structure is
broken down into separate modules. This allow the program to be loaded efficiently into
the memory and also be reused in other programs. Modules are coded separately, tested
individually and then integrated to form overall program structure. It is easier to debug
and understand the program.
Advantages
a) Easy to understand and change.
b) Many programmer can work on different modules of large program.
c) Can be written in less time.
d) Module or procedures written once can be reused in other program.
e) Easy to debug.
Disadvantages
a) Not data centered
b) Global data is shared and gets modified.
Global Data
Modules that have
local data and code
Program
Object 1
Object 2
Object 3
Object 3
Requirements analysis
In this space the uses expectations are gathered to know why the program or software has to be
built. All the gather requirements are analysed the objective of the software product. Every
identify requirement of the users are documented to avoid any doubts.
The functionality capability performance and availability of hardware and software components
are analysed in this face.
Design
In design phase plan of action is made before the actual development process can start. The
requirements documented in the previous phase acts as input for the design paste. In this space
the structure of the program is broken down into modules. The solution for each modules is
specified in the form of algorithms or flowcharts.
Implementation
In this phase the designed algorithm are converted into program code using any high level
language. This phase is also called as construction of food generation phase.
Testing
In this phase all the modules are tested together to ensure it the overall system works well. The
software is tested using a large number of varied inputs also known as test data to ensure with the
software is working as expected by the user requirement.
Software deployment training and support
In this phase the software is installed or deployed in the production environment. Maintenance
and enhancements are the ongoing activity that are done to cope up with newly discovered
problems for your requirements.
Requirements
analysis
Design
Implementation
Testing
Software
deployment,
training, and
support
Maintenance
Repetition
Reputation involves executive one or more steps for a number of times. It can be executed using
construct such as while do while and for loops.
Example
Step 1: [INITIALIZE] set I-1, N=10
Step 2: Repeat steps 3 and 4 while I<=N
Step 3: PRINT I
Step 4:SET I+1
[end of loop]
Step 5:END.
2.Flowchart
A flowchart is a graphical or symbol representation of a process. When designing the floor chart,
in the process is depicted by different symbols and is associated with a short description. The
symbols in the flowchart are linked together with arrow to show the flow of logic in the process.
Pseudocodes
Pseudocode is a compact and informal high level description of an aquarium that uses the
structural convention of a programming language. It is basically meant for human reading rather
than machine reading so it omits that details that are not essential for humans. They consists of
short English phrase the explain specific task within a programs algorithm. The soul purpose of
the seed of course is to enhance human understand ability of the solution. There are no standards
defined for writing pseudo code, because a pseudo code is not an executable program. Flowcharts
can be considered as an alternative to the pseudocode but require more space on paper.
Example : pseudocode to add two numbers.
1. Read the first number A.
2. Read the second number B
3. Find the sum =A+B
4. Print sum.
Types of errors
While writing programs very awesome needed errors in our programs. These errors if not
removed to either give erroneous output or you not read the compiler compile the program. These
errors are broadly classified into four types.
Types of
errors
1. Runtime errors- occur in the program is being Run executed. Such errors occur in the
program performs some illegal operations like
Dividing a number by zero
Opening a file that already exist
Lack of free memory space
Finding Where are logarithm of negative numbers
Run time errors may terminate program execution, so the code must be written in such a way
that it handles all sort of unexpected errors.
2. Compile time errors- occurs at the time of compilation of the program. Such errors may be
further classified as
Syntax errors- are generated on rules of programming languages.
Semantic errors - those which make comply with the programming language but I not
meaning to be the compiler.
3. Logical errors- errors in the program for that results in unexpected and undesirable output.
Such errors are not detected by the compiler and the programmers must check the code and
rectify the errors.
4. Linker errors- linker is not able to find the function definition for a given prototype.
Testing and debugging approaches
Testing is an activity that is perform to verify the correct behaviour of the program. It is carried
out with an intent to find error. There are three types of testing
Unit test- unit testing is applied only on a single unit or module of a program.
Integration testing- two units that have already been tested are combined into a
component and the interface between the mistake.
system test- system testing check the entire system.
Debugging- is an activity that includes extension execution testing and core correction. The main
aim of debugging is locating errors in the program code. Once the years are located, there
isolated and fixed to produce error free code. Different approaches applied for debugging a
coding includes
Brute force method
Back tracking method
Cause elimination
Introduction to C programming:
C is a general purpose, structured programming language. It bridges the gap between
machine language and conventional high-level languages. This flexibility allows c
language to be used for system programming as well as for applications programming.
C is a powerful language that provides fast program execution. Its power and fast
program execution come from its ability to access low commands similar to assembly
language but with high level syntax.
History of C language:
Features of C language:
Simple robust:
C is a general purpose, structured programming language. It has the simplicity of a high level
language as well as the power of low level language. This aspect of c makes it suitable for
writing both application programs and system programs. Hence it is an excellent, efficient and
general purpose language for most of the application such as mathematical, scientific, business
and system software applications.
Modularity:
C programs are modular in nature it supports compartmentalization of code and data. This
capability makes it very easy for c-programs to share sections of code. We can divide c programs
to several modules that will combine in a single module to build the final program.
Extensibility:
The c language is extensible since it allows the users to add their own library function to the
library function .section of code or modules can be stored in libraries for re-use them in future.
Portability:
C program written on one computer or operating system can be compiled and run on another
computer or operating system with little or no modification.
The compilation and execution of c programs are faster than modern programming languages.
This is due to its variety of data type and powerful operators.
Bit manipulation:
It provides wide variety of bitwise operators to manage data at bit level. We can perform
different operations at bit level
The declaration section- the data are declared within a function are known as local declaration
as the data will be visible only within the function.
The statement section in the function contains the code to perform specified task.
Preprocessor derectives
Global Declaration
main( )
{
Local declarations
Statements
}
Function 1( )
{
Local declarations
Statements
}
………………….
Function N( )
{
Local declarations
Statements
}
#include<stdio.h>
int main()
{
printf(“welcome to the world of C\n”);
return 0;
}
# include<stdio.h>
This is a processor command that comes at the first statement in our code. All preprocessor
commands start with the symbol hash(#). The # include statement tells the compiler to
include standard input/ output library or file in the program. This file has some inbuilt
functions which can be used directly in the court by just including this file the program. The
standard input output library contains functions to read the data from the keyboard and
printing the result on the screen.
int main()
Every C program contains a main() function which is starting point of the program. int is the
return value of the main() function. Statement written and integer value to the operating
system. To curly brackets{ } are used to group all the related statements in the main
function. The statement within the braces from the function body.
The printf function is defined in the stdio.h header file.
Example:
//Addition of two numbers
#include<stdio.h>
void main( )
{
int a, b, sum;
printf(“Enter two numbers\n”);
scanf(“%d%d”, &a, &b);
sum = a + b;
printf(“The sum is %d”, sum);
}
Files used in C
Source file:
The source code file contains the source code of the program.
The file extension of any C source code file is ‘.c’. This file contains C source code that
define the main function and may be other functions. The main () function is the starting
point of execution when you successfully compile and run the program.
Header file:
When working with large projects, it is often desirable to separate out certain sub routines
from the main () of the program.
There also may be a case that the same subroutine has to be used in different programs. In
the latter case one option is to copy the code of the desired subroutine from one program
to another. However copying the code is often tedious as well as error-prone and makes
maintainability more difficult.
Example:
Object file:
Object files are generated by the compiler as a result of processing the source code file. They
contain compact binary code of the function definition.
Executable file
Linker uses this object file to produce an executable file (.exe file) by combining the object files
together. Object file have a ‘.o’ extension.
4. Executing programs(file.exe) :
Executable file is ready to run file. Loader loads the executable file into the main/primary
memory and run program.
Object
file
Compilers:
A compiler is a program that translate the instruction of high level language (source code)
into machine language (object language)
A compiler is a program or set of programs that converts source code written in a high
level language to low level language (assembly language or machine language)
A programming language can have many compilers. For example, GCC,turbo C,Quick C
etc.. are different compilers for C programming language.
Need of compiler:
A computer understands only binary language and executes instructions coded in binary
language. It cannot execute a single instruction given in any other form. Therefore we
must provide instructions to the computer in binary language.
Means we must write computer programs entirely in binary language and it is not
possible to write the program in binary language.’
So there was a need of a translator that translates the compiler instructions given in
English language to binary language.
Compiler interpreter
Compiler takes entire program as input Interpreter takes single instructions as input
Compiler generates object code Interpreter is not generates object code.
No source code is required in executable file Source code is required in executable file
Programming language like C,C++,C# uses Programming language like python ,ruby uses
compilers interpreters.
Compiler translates entire program at a time Interpreter translates program line by line
Using Comments
Comments in C language are used to provide information about lines of code. It is widely used for
documenting code. There are 2 types of comments in the C language.
Single Line Comments-Single line comments are represented by double slash \\. Let's see an
example of a single line comment in C.
#include<stdio.h>
int main(){
//printing information
printf("Hello C");
return 0; // returns zero value
}
Multi Line Comments- Multi-Line comments are represented by slash asterisk \* ... *\. It can
occupy many lines of code, but it can't be nested.
#include<stdio.h>
int main(){
/*printing information
Multi-Line Comment*/
printf("Hello C");
return 0;
}
C Tokens
Tokens are basic building blocks of C. it is the smallest individual unit in a C program. The
program is constructed using a combination of these tokens.
Character set:
In the C programming language, the character set refers to a set of all the valid characters that we
can use in the source program for forming words, expressions, and numbers.
keywords:
Keywords are meant for some special purpose called as reserved words.
They are sequence of characters with fixed meaning.
User cannot change the meaning of keywords.
Identifiers:
Identifiers are the names given to the elements of the program such as variable name ,
name or a function name.
An identifier is a word consisting of sequence of one or more letters or digits or a special
symbol called as _(underscore)
Rules:
Constants:
Constants are the data values that cannot be change during the execution of a program.
Operators:
Special symbol:
Special symbols have some special meaning in the c programming language for the compiler and
it is used to perform some special function\task in c.
Primary/ Built-in/ Fundamental data type: These are the built in data types
available in C. There are5 types. Namely:
1. Integer (int)
2. Floating point (float)
3. Character (char)
4. Double precision floating point (double)
5. Void (void)
1. Integer Type
It is used to store whole numbers.
The keyword int is used to declare variable of integer type.
Int type takes 2B or 4B of storage depending on machine size.
The classes of integer are:
Unsigned Signed
Data type Keyword Size Data type Keyword Size
Short Integer short int 1B Signed short integer signed short int 1B
Integer int 2B Signed integer signed int 2B
Long Integer long int 4B Long integer long int 4B
2. Floating point data type:
It is used to store decimal numbers.
The keyword float is used to declare variable of floating point data type.
Float type takes 4B or 8B of storage depending on machine size.
It can be expressed in fractional or exponential form.
3. Double:
It is used to store double precision floating point numbers.
The keyword double is used to declare variable of floating point data type.
Double type takes 8B of storage.
Double precision is related to accuracy of data.
4. Char:
It is used to store character type of data.
The keyword char is used to declare variable of character type.
Char type takes 1B of storage.
5. Void:
It is a special data type that has no value.
It doesn’t have size.
It is used for returning the result of function that returns nothing.
Variable
A variable is a name given to memory location whose value changes duringexecution.
Types of variables:
1. Numeric variable: numeric variable can be used to store either integer values or floating
point values.
2. Character variable:
Character variable can include any letter from the alphabet or from the ASCII chart and
number from 0-9 that are given within single quotes.
Declaration:
Syntax: datatype variable_list;
Where,
datatype Any built in data type
variable_list Identifiers that specifies variable name.
Example: int a;
Initialization:
Example: int a = 5;
2. Character constants:
A character constant contains one single character enclosed within single quotes (‘’)
Example:
‘a’, ’Z’,’\n’
3. String constants:
String constant are sequence of character enclosed within double quotes (‘””).
Example:
“hello”,”1234”,”abc”,”\n”
Declaring constants:
1. To declare a constant precede the normal variable declaration with const keyword and
assign it a value.
Syntax: const data type constant value
Example: const float Pi=3.142
2. Another way is to use the preprocessor command define.
Syntax: #define const value
Example:
#define PI 3.142
We use the scanf() function for getting the formatted inputs or standard inputs so that the printf ()
function can provide the program with numerous options of conversion.
Syntax for scanf()
The purpose of the scanf() function is to read the characters that we get from the standard input,
convert them according to the string of format specification, and then store the available inputs in
the memory slots that the other arguments represent
Inputting Values Using scanf- To enter the input through the input devices like keyboard we
make use of scanf statement.
General Syntax:
scanf (format_specifier, &data_a, &data_b,……); // Here, & refers to the address operator
Where: Format string consists of the access specifiers/format specifiers.
Format string also called as control string.
Format string consist of format specifier of particular data type
Format specifiers starts with % sign followed by conversion code.
List of addresses of variables consist of the variable name preceded with &
symbol(address operator).
Example:int a; float b;
scanf(“%d%f”,&a,&b);
Rules for scanf
No escape sequences or additional blank spaces should be specified in the format
specifiers.
Ex: scanf(“%d %f”,&a,&b); //invalid scanf(“%d\n%f”,&a,&b); //invalid
& symbol is must to read the values, if not the entered value will not be stored in the
variable specified. Ex: scanf(“%d%f”,a,b);//invalid.
We use this function for displaying a single or multiple values in the form of output for the user
end at the console.
printf is an output statement in C used to display the content on the screen.
print: Print the data stored in the specified memory location or variable.
Format: The data present in memory location is formatted in to appropriate data type.
There are various forms of printf statements.
output:
integer=10, floating=20.00000
Symbols Meaning
%c Character
%o octal number
%s String
%lf double
#include <stdio.h>
int main()
{
int i;
float f;
char c;
printf("You entered:\n");
printf("i = %d, f = %f, c = %c\n", i, f, c);
Questions
1. Define computer. Describe the various types of computers based on speed, memory and cost.
2. Discuss the variants of microcomputer that are widely used today.
3. Explain the components of a computer with a neat diagram.
4. Write a short note on the characteristics of a computer.
5. Mention various output devices and explain hardcopy devices. Describe any three input devices
6. Develop an algorithm to find the area and perimeter of a circle. Also define an algorithm.
7. Draw a flowchart and C program which takes as input p,t,r. Compute the simple interest and
display the result.
8. Design an algorithm, flowchart and program to compute area of a circle.
9. Explain the structure of C program in detail. Write a sample program to demonstrate the
components in the structure of C program.
10. Discuss different types of error occur in program.
11. What is variable? What are the rules to construct variable? Classify the following as valid/invalid
Identifiers. i) num2 ii) $num1 iii) +add iv) a_2 v) 199_space vi) _apple vii)#12
12. Write a note on the following operators. i) Relational ii) Logical iii) Conditional
13. Demonstrate formatted output of integer in C with suitable example.
14. Summarize the formatted input and output statements with suitable syntax and example
15. Explain the SDLC life cycle for the efficient design of a program with a neat diagram.
16. What are the basic datatypes available in C.