Data types specify how we enter data into our programs and what type of data we enter.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.
They are arithmetic types and are further classified into: (a) integer types and (b) floating-point types.
They are again arithmetic types and they are used to define variables that can only assign certain discrete integer values throughout the program.
The type specifier void indicates that no value is available.
They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.
Data type determines the type of data a variable will hold. If a variable x is declared as int. it means x can hold only integer values. Every variable which is used in the program must be declared as what data-type it is.
Type | Size (bytes) | Format Specifier |
---|---|---|
int | at least 2, usually 4 | %d |
char | 1 | %c |
float | 4 | %f |
double | 8 | %lf |
short int | 2 usually | %hd |
unsigned int | at least 2, usually 4 | %u |
long int | at least 4, usually 8 | %li |
long long int | at least 8 | %lli |
unsigned long int | at least 4 | %lu |
unsigned long long int | at least 8 | %llu |
signed char | 1 | %c |
unsigned char | 1 | %c |
long double | at least 10, usually 12 or 16 | %Lf |
Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.
For Example: enum flag {const1, const2, ..., constN};
By default, const1 is 0, const2 is 1 and so on
The void type specifies that no value is available. It is used in three kinds of situations −
There are various functions in C which do not return any value or you can say they return void. A function with no return value has the return type as void. For example, void exit (int status);
There are various functions in C which do not accept any parameter. A function with no parameter can accept a void. For example, int rand(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 casted to any data type.
Derived data types are nothing but primary datatypes but a little twisted or grouped together like array, stucture, union and pointer. These are discussed in details later.