Data Types in C
1.4 Data types
As in our daily languages
we have different alphabets, numbers and special characters, in C we have many
“data types”. These could be defined as the fundamental blocks by which define
how any form of data is to be stored and processed.
These data types may be
different based on compilers, but in general C data types are classified into
fundamental, derived and programmer-defined data types.
C programming basic data types |
Fundamental data types
are namely void, int, float, char, long, double, * (pointer type).
Derived data types
include arrays, string and structures.
Programmer defined data
types include Structure, Union and Enumerations.
Let’s keep it short and
define only the essential ones as you’ll have separate tutorials on some data
types.
1.
Int: This data type indicates integer numbers and
it is represented by “int” keyword
in C. Integers consume storage space of 2 bytes and range from -32,768 to
32,768.
2.
Long: This
data type is similar to Int but it takes more memory i.e. 4 bytes and has
higher range. It is represented by keyword “long”.
3.
Float: This
data type indicates floating point numbers (decimals) and it is represented by
“float” keyword in C. They consume
storage space of 4 bytes and range from 1.2E-38 to 3.4E+38. They have precision
only up to 6 decimal places.
4.
Double: It’s
similar to the float but has higher precision of 15 decimal places and consumes
memory of 8 bytes with much broader range. It is represented by “double” keyword.
5.
Char: This
data type indicates characters and they are represented by “char” keyword in C. They consume
storage space of 1 byte and range from ASCII character values of -128 to 127 or
0 to 255.
6.
Void: As
we have zero (0) in our language which means the one which has no intrinsic
value, Void data type represents the same in C. It is represented by keyword “void”.
Here I must mention that
there are certain qualifiers i.e. keywords which will extend the range,
precision etc. for the data types.
Keywords like “signed”, “unsigned” may be used in combinations with above data types in
order to increase range, or the precision of the data type. For example, “unsigned long” has two keywords combined and we have range of integers from
0 to 4,294,967,295.
In some cases, “long double” is used with precision up
to 19 decimal places and range of 3.4E-4932 to 1.1E+4932. Although combining
keywords will increase range and precision but it also consumes more memory.
These data types as
defined indicates the compiler as how data will be stored and processed. For
example, data types are used in declaring variables. Variables in C are simply
memory allocations made to any data. These memory allocations are named by the
user and defined by the data types, so as to tell the amount of memory to be
allocated.
Comments
Post a Comment