Data
Types in C
A data type or
simply type is an attribute of data which
tells the compiler or interpreter how the programmer intends to use the data.
... This data type defines the operations that can be done on
the data, the meaning of the data, and the way values
of that type can be stored.
·
Primary data types: These are fundamental data
types in C namely integer( int ), floating point( float ), character(
char ) and void .
·
Derived data types: Derived data types are
nothing but primary datatypes but a little twisted or grouped
together like array, structure, union and pointers.
There are some common data types in C − int − Used to store an integer value. char − Used to store a single character. float − Used to store decimal numbers with single precision. double − Used to store decimal numbers with double precision.
types in C − int − Used to store an integer value. char − Used to store a single
character. float − Used to store
decimal numbers with single precision. double − Used to store decimal numbers with double precision.
Basic types
This table contains some commonly using types in C
programming.
Type |
Size (bytes) |
Format Specifier |
|
at least 2, usually 4 |
|
|
1 |
|
|
4 |
|
|
8 |
|
|
2 usually |
|
|
at least 2, usually 4 |
|
|
at least 4, usually 8 |
|
|
at least 8 |
|
|
at least 4 |
|
|
at least 8 |
|
|
1 |
|
|
1 |
|
|
at least 10, usually 12 or 16 |
|
int -
Integer data type allows
a variable to store numeric values. “int” keyword is used to
refer integer data type. ... int (2 byte) can store values from -32,768
to +32,767. int (4 byte) can store values from -2,147,483,648 to
+2,147,483,647.
Float & Double -
While float has 32 bit precision for floating number
(8 bits for the exponent, and 23* for the value), i.e. float has
7 decimal digits of precision. As double has more precision as
compare to that of flot then it is much obvious that it occupies twice memory
as occupies by the float data type.
Char - The
abbreviation char is used as a reserved keyword in some
programming languages, such as C, C++, C#, and Java. It
is short for character, which is a data type that holds one character (letter,
number, etc.) of data. For example, the value of a char variable
could be any one-character value, such as 'A', '4', or '#'. Now character datatype
can be divided into 2 types:
signed char and unsigned char.
·
signed
char - The signed char type
can store , negative , zero , and positive integer values . It has a minimum
range between -127 and 127 , as defined by the C standard .
·
unsigned
char -unsigned char is a character datatype
where the variable consumes all the 8 bits of the memory and there is no sign
bit (which is there in signed char). So it means that the range
of unsigned char data type ranges from 0 to 255.
Void -
void is used as a function return type, it
indicates that the function does not return a value. When void appears
in a pointer declaration, it specifies that the pointer is universal. When used
in a function's parameter list, void indicates that the
function takes no parameters.
Short & Long - The main
difference between them is their size. Depending on the computer but in most
cases a "short" is two bytes a "long" is four
bytes and an "int" can be two or four bytes. The minimum size for
char is 8 bits, the minimum size for short and int is 16 bits,
for long it is 32 bits and long long must
contain at least 64 bits. ... In practice, char is usually 8 bits in size
and short is usually 16 bits in size (as are their unsigned
counterparts). If you need to use a large
number, you can use a type specifier long.
Derived
Data Types
Derived data type
is the aggregation of fundamental data type. character,
integer, float, and void are fundamental data types. Pointers,
arrays, structures and unions are derived data types.
·
Array, pointers, struct,
and union are the derived data types in C.
·
Unsigned long int: 0
to 4,294,967,295 (4 bytes)
·
Data type: Range
·
Signed long int: -2,147,483,648 to
2,147,483,6...
·
Unsigned int: 0 to 65,535