C - Data Types
Data Types in C
Each variable in C has an associated data type.
Each data type requires different amounts of memory and has some specific
operations which can be performed over it. It specifies the type of data that
the variable can store like integer, character, floating, double, etc. 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 Types |
Arithmetic types can be further
classified into integer and floating data types. |
Void
Types |
The data type has no value or
operator and it does not provide a result to its caller. But void comes under
Primitive data types. |
User
Defined DataTypes |
It is mainly used to assign
names to integral constants, which make a program easy to read and maintain |
Derived
types |
The data types that are derived
from the primitive or built-in datatypes are referred to as Derived Data
Types. |
Data Type |
Memory (bytes) |
Range |
Format Specifier |
short int |
2 |
-32,768 to
32,767 |
%hd |
unsigned short
int |
2 |
0 to
65,535 |
%hu |
unsigned int |
4 |
0 to
4,294,967,295 |
%u |
int |
4 |
-2,147,483,648
to 2,147,483,647 |
%d |
long int |
4 |
-2,147,483,648
to 2,147,483,647 |
%ld |
unsigned long
int |
4 |
0 to
4,294,967,295 |
%lu |
long long
int |
8 |
-(2^63) to
(2^63)-1 |
%lld |
unsigned long
long int |
8 |
0 to
18,446,744,073,709,551,615 |
%llu |
signed
char |
1 |
-128 to
127 |
%c |
unsigned
char |
1 |
0 to 255 |
%c |
float |
4 |
1.2E-38 to
3.4E+38 |
%f |
double |
8 |
1.7E-308 to
1.7E+308 |
%lf |
long
double |
16 |
3.4E-4932 to 1.1E+4932 |
%Lf |
Integer Types :
The integer data type in C is used to store the whole numbers without
decimal values. Octal values, hexadecimal values, and decimal values can be
stored in int data type in C. We can determine the size of the int data type by
using the sizeof operator in
C. Unsigned int data type in C is used to store the data values from zero to
positive numbers but it can’t store negative values like signed int. Unsigned
int is larger in size than signed int and it uses “%u” as a format specifier in
C programming language. Below is the programming implementation of the int data
type in C.
·
Range: -2,147,483,648
to 2,147,483,647
·
Size: 2 bytes or 4 bytes
·
Format Specifier: %d
Note: The size of an integer data type is compiler-dependent, when processors
are 16-bit systems, then it shows the output of int as 2 bytes. And when
processors are 32-bit then it shows 2 bytes as well as 4 bytes.
Character Types :
Character data type allows its variable to store only a single character.
The storage size of the character is 1. It is the most basic data type in C. It
stores a single character and requires a single byte of memory in almost all
compilers.
·
Range: (-128 to 127) or (0 to 255)
·
Size: 1 byte
·
Format Specifier: %c
Floating-Point Types :
In C programming float data type is used to store floating-point values.
Float in C is used to store decimal and exponential values. It is used to store
decimal numbers (numbers with floating point values) with single precision.
·
Range: 1.2E-38 to 3.4E+38
·
Size: 4 bytes
·
Format Specifier: %f
Double Types :
A Double data type in C is used to store decimal numbers
(numbers with floating point values) with double precision. It is used to
define numeric values which hold numbers with decimal values in C. Double data
type is basically a precision sort of data type that is capable of holding 64
bits of decimal numbers or floating points. Since double has more precision as
compared to that float then it is much more obvious that it occupies twice the
memory as occupied by the floating-point type. It can easily accommodate about
16 to 17 digits after or before a decimal point.
·
Range: 1.7E-308 to 1.7E+308
·
Size: 8 bytes
·
Format Specifier: %lf
Void Data types :
The void data type in C is used to specify
that no value is present. It does not provide a result value to its caller. It
has no values and no operations. It is used to represent nothing. Void is used
in multiple ways as function return type, function arguments as void, and pointers to void.
Comments
Post a Comment