Session 3 - Data Types
Session 3 - Data Types
3.1 Introduction
3.2 Learning Outcomes
3.3 Data types in C
3.4 Integer types
3.5 Floating point types
3.6 Character Types
3.7 Summary
3.1 Introduction
As the name suggests, a data type specifies the type of data that a variable
can store such as integer, floating, character, etc. Whenever we define a
1
variable or use any data in the C language program, we have to specify the
type of the data, so that the compiler knows what type of data to expect. A
variable can be seen as a temporary memory location used to store data.
a. Variables
Variable is an identifier used to store values in it. For example: a,b,c, etc. A
variable is nothing but a name given to a storage area that a programs can
manipulate. Each variable in C has a specific type, which determines:
ii. the range of values that can be stored within that memory;
iii. and the set of operations that can be applied to the variable.
b. Data Types
Each variable that we declare in a C program must have a data type. Data
type tells:
1. Integer types
3. Character Types
2
(i) int or signed int or short
Space 2 bytes
Type of value Integer type
Range -32768 to
+32767
Format %d
specifier
Space 2 bytes
Type of value Integer
type
Range 0 to
+65535
Format %ud
specifier
Space 4 bytes
Range -2,147,483,648 to
+2,147,483,647
Format %ld
specifier
Space 4 bytes
3
Type of value Integer type
Range 0 to +
4,294,967,295
Format %lu
specifier
(i) float
Space 4 bytes
Range -3.4E-38 to
+3.4E+38
Format %f
specifier
(ii) double
Space 8 bytes
Range -1.7E-308 to
+1.7E+308
Format %lf
specifier
Space 10 bytes
4
Type of value Real type
Range -3.4E-4932 to
+1.1E+4932
Format %Lf
specifier
Space 1 byte
Format %c
specifier
Space 1 byte
Range 0 to +255
Format %c
specifier
3.7 Summary
In this session, we have learned about the categories of data types which
include Integer types, Floating point types and Character Types. We have also
learnt the relationship between data types and variable. In our next session
5
we will learn the basic structure of a C program and write a simple program
to implement what we have learnt so far.