Data Types in C
•
••
Each variable in C has an associated data type. It specifies the type of data that the
variable can store like integer, character, floating, double, etc. Each data type
requires different amounts of memory and has some specific operations which can
be performed over it. The data type is a collection of data with values having fixed
values, meaning as well as its characteristics.
The data types in C can be classified as follows:
Types Description
Primitive Data Primitive data types are the most basic data types that are used for
Types representing simple values such as integers, float, characters, etc.
User Defined
The user-defined data types are defined by the user himself.
Data Types
The data types that are derived from the primitive or built-in
Derived Types
datatypes are referred to as Derived Data Types.
Different data types also have different ranges up to which they can store numbers.
These ranges may vary from compiler to compiler. Below is a list of ranges along
with the memory requirement and format specifiers on the 32-bit GCC compiler.
, Size Format
Data Type (bytes) Range Specifier
short int 2 -32,768 to 32,767
%hd
unsigned short
2 0 to 65,535 %hu
int
unsigned int 4 0 to 4,294,967,295 %u
-2,147,483,648 to
int 4 %d
2,147,483,647
-2,147,483,648 to
long int 4 %ld
2,147,483,647
unsigned long
4 0 to 4,294,967,295 %lu
int
signed char 1 -128 to 127 %c
unsigned char 1 0 to 255 %c
float 4 %f
1.2E-38 to 3.4E+38
double 8 %lf
1.7E-308 to 1.7E+308
•
••
Each variable in C has an associated data type. It specifies the type of data that the
variable can store like integer, character, floating, double, etc. Each data type
requires different amounts of memory and has some specific operations which can
be performed over it. The data type is a collection of data with values having fixed
values, meaning as well as its characteristics.
The data types in C can be classified as follows:
Types Description
Primitive Data Primitive data types are the most basic data types that are used for
Types representing simple values such as integers, float, characters, etc.
User Defined
The user-defined data types are defined by the user himself.
Data Types
The data types that are derived from the primitive or built-in
Derived Types
datatypes are referred to as Derived Data Types.
Different data types also have different ranges up to which they can store numbers.
These ranges may vary from compiler to compiler. Below is a list of ranges along
with the memory requirement and format specifiers on the 32-bit GCC compiler.
, Size Format
Data Type (bytes) Range Specifier
short int 2 -32,768 to 32,767
%hd
unsigned short
2 0 to 65,535 %hu
int
unsigned int 4 0 to 4,294,967,295 %u
-2,147,483,648 to
int 4 %d
2,147,483,647
-2,147,483,648 to
long int 4 %ld
2,147,483,647
unsigned long
4 0 to 4,294,967,295 %lu
int
signed char 1 -128 to 127 %c
unsigned char 1 0 to 255 %c
float 4 %f
1.2E-38 to 3.4E+38
double 8 %lf
1.7E-308 to 1.7E+308