What is Data Type
A type of data is called the data type (or in simple word we can say type of variable is called data type) and its true for all compiler based computer languages where as in most of the interpreter based language a variable type is not fixed rather dependent at the usage at a particular instance.
Classification of Data Types
In C we can classify the data types in four ways -
1. Basic Types:
Basic Data types are arithmatic data types and can be of two types i.e.
(a) integer types (char is also an integer)
Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
(b) floating-point types.
Type Storage Size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places
2. Enumerated types:
They are again arithmetic types and they are used to define variables that can only be assigned certain discrete integer values throughout the program.
Example
enum month { jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec };
enum month this_month;
In the above declaration, month is declared as an enumerated data type. It consists of a set of values, jan to dec. Numerically, jan is given the value 1, feb the value 2, and so on dec as 12. So variable this_month can take any value from 1 to 12 as an integer or jan to dec as enum.
3. The type void:
The type specifier void indicates that no value is available. there can be three cases which can be described as void data types in C.
(a) Function returns as void
A function which do not return value or you can say they return void.
(b) Function arguments as void
A function with no parameter can accept void as parameters. For example, int myfunc(void);
(c) Pointers to void
A pointer of type void * represents the address of an object, but not its type. For example a memory allocation function void *malloc( size_t size ); returns a pointer to void which can be type casted to any data type.
4. Derived types:
These are
(a) Pointer types
(b) Array types
(c) Structure types
(d) Union types and
(e) Function types