C Data Type
C programming supports several data types for storing different types of values. In this answer, we will discuss the basic C data types, their sizes, and their ranges.
Basic C Data Types:
C programming supports the following basic data types:
- char
- int
- float
- double
- void
We will discuss each of these data types in detail.
- char:
The char data type is used to store a single character. It is represented using the keyword ‘char’. The size of a char is 1 byte, and its range is -128 to 127 or 0 to 255, depending on whether it is signed or unsigned. The default type of char is signed.
Signed char:
Data type | Storage size | Value range |
---|---|---|
char | 1 byte | -128 to 127 |
Unsigned char:
Data type | Storage size | Value range |
---|---|---|
unsigned char | 1 byte | 0 to 255 |
- int:
The int data type is used to store integers. It is represented using the keyword ‘int’. The size of an int is typically 4 bytes on most systems, although this can vary depending on the system architecture. The range of an int is -2,147,483,648 to 2,147,483,647. The default type of int is signed.
Signed int:
Data type | Storage size | Value range |
---|---|---|
int | 4 bytes | -2,147,483,648 to 2,147,483,647 |
Unsigned int:
Data type | Storage size | Value range |
---|---|---|
unsigned int | 4 bytes | 0 to 4,294,967,295 |
- float:
The float data type is used to store single-precision floating-point numbers. It is represented using the keyword ‘float’. The size of a float is 4 bytes, and its range is approximately 1.2E-38 to 3.4E+38.
Data type | Storage size | Value range |
---|---|---|
float | 4 bytes | 1.2E-38 to 3.4E+38 |
- double:
The double data type is used to store double-precision floating-point numbers. It is represented using the keyword ‘double’. The size of a double is 8 bytes, and its range is approximately 2.3E-308 to 1.7E+308.
Data type | Storage size | Value range |
---|---|---|
double | 8 bytes | 2.3E-308 to 1.7E+308 |
- void:
The void data type is used to indicate the absence of a value. It is represented using the keyword ‘void’. The void data type cannot be used to declare variables, but it is commonly used as a return type for functions that do not return a value.
Data type | Storage size | Value range |
---|---|---|
void | N/A | N/A |
Conclusion:
In this answer, we discussed the basic data types supported by C programming, their sizes, and their ranges. It is important to understand the characteristics of each data type in order to use them effectively in C programs. By using the appropriate data type for each variable, we can ensure that our programs are efficient and accur