SESSION THREE
DATA TYPES IN C LANGUAGE
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
In this session, we will learn about different data types used in C
programming language. In our previous session, we learnt that variables are
named memory locations for storing data that is used during program
execution. This session will discuss in details different types of data that a
can be stored in a variable. Welcome!!!
3.2 Learning Outcomes
At the end of this session, you should be able to:
Demonstrate knowledge and understanding of data
types in C language and their properties.
To declare, define and initialize a variable.
Create and use data types in a C program
3.3 Data Types in C
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:
i. the size and layout of the variable's memory;
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. Size of space occupied by that variable.
2. Type of value that can be stored in that variable.
3. Range of value that can be stored in that variable.
4. Format specifier (how C will recognize the data type of variable)
In C, there are 3 categories of data types-
1. Integer types
2. Floating point types
3. Character Types
3.4 Integer types
2
(i) int or signed int or short
Space 2 bytes
Type of value Integer type
Range -32768 to
+32767
Format %d
specifier
(ii) unsigned int or unsigned short
Space 2 bytes
Type of value Integer
type
Range 0 to
+65535
Format %ud
specifier
(iii) long or long int or signed long int
Space 4 bytes
Type of value Integer type
Range -2,147,483,648 to
+2,147,483,647
Format %ld
specifier
(iv) unsigned long or unsigned long int
Space 4 bytes
3
Type of value Integer type
Range 0 to +
4,294,967,295
Format %lu
specifier
3.5. Floating Point types-
(i) float
Space 4 bytes
Type of value Real type
Range -3.4E-38 to
+3.4E+38
Format %f
specifier
(ii) double
Space 8 bytes
Type of value Real type
Range -1.7E-308 to
+1.7E+308
Format %lf
specifier
(iii) long double
Space 10 bytes
4
Type of value Real type
Range -3.4E-4932 to
+1.1E+4932
Format %Lf
specifier
3.6 Character types
(i) char or signed char
Space 1 byte
Type of value Character type
Range -128 to +127
Format %c
specifier
(ii) unsigned char
Space 1 byte
Type of value Character type
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.