Data types in c refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. It is a type of data that a variable holds. These are used for assigning a type to a variable.
Table of Contents
Types of C Data types
- Basic types: Integer type and Floating type
- Enumerated type: They are used to define variables that can only assign certain discrete integer values throughout the program.
- Void type: It is a data types which denotes no value which means no data type.
- Derived data types: They include the following
- (a) Pointer types
- (b) Array types
- (c) Structure types
- (d) Union types
- (e) Function types
1. Integer Types
The following table provides the details of standard integer types with their storage sizes and value ranges
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 | 8 bytes | -9223372036854775808 to 9223372036854775807 |
unsigned long | 8 bytes | 0 to 18446744073709551615 |
To get the size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. Given below is an example to get the size of various types
#include <stdio.h>
int main()
{
printf("%lu",sizeof(int));
return 0;
}
2. Floating-Point Types
The following table provide the details of standard floating-point types with storage sizes and value ranges and their precision
Type | Storage size | Value range |
float | 4 byte | 1.2E-38 to 3.4E+38 |
double | 8 byte | 2.3E-308 to 1.7E+308 |
long double | 10 byte | 3.4E-4932 to 1.1E+4932 |
3. Void type
In computer programming, when 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.
Void as a Function Return Type Void functions, also called non value-returning functions, are used just like value-returning functions except void return types do not return a value when the function is executed.
4. Pointer type
Pointer is a user defined data type which creates special types of variables which can hold the address of primitive data type like char, int, float, double or user defined data type like function, pointer, etc. or derived data type like an array, structure, union, enum.
5. Array type
An array is a group (or collection) of same data types. For example an int array holds the elements of int types while a float array holds the elements of float types.
6. Structure data types
A structured data type is one in which each data item is a collection of other data items. In a structured data type, the entire collection uses a single identifier (name). The purpose of structured data types is to group related data of various types for convenient access using the same identifier.