A data type in c programming language specifies the type of data that a variable can store. There are the following data types in C language.
SL No | Data Types |
---|---|
1. | Basic Data Types : int, char, float, double |
2. | Derived Data Type : array, pointer, structure, union |
3. | Enumeration Data Type : enum |
4. | Void Data Type : void |
Basic Data Types : The basic data types are integer-based and floating-point based. C language supports both signed and unsigned literals.
The following table provides the details of standard integer types with their storage sizes and value ranges :
Types | 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 |
To get the exact 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 int type on any machine :
#include<stdio.h>
#include<limits.h>
int main()
{
printf("Storage size for int : %d \n", sizeof(int));
return 0;
}
printf("Storage size for int : %d \n", sizeof(int));
return 0;
}
Output :
Storage size for int : 4
The following table provides the details of standard floating types with storage sizes and value ranges :
Types | 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 |
The following example prints the storage space taken by a float type and its range values :
#include<stdio.h>
#include<float.h>
int main()
{
printf("Storage size for float : %d \n", sizeof(float));
printf("Minimum float positive value: %E\n", FLT_MIN );
printf("Maximum float positive value: %E\n", FLT_MAX );
printf("Precision value: %d\n", FLT_DIG );
return 0;
}
#include<float.h>
int main()
{
printf("Storage size for float : %d \n", sizeof(float));
printf("Minimum float positive value: %E\n", FLT_MIN );
printf("Maximum float positive value: %E\n", FLT_MAX );
printf("Precision value: %d\n", FLT_DIG );
return 0;
}
Output :
Storage size for float : 4
Minimum float positive value: 1.175494E-38
Maximum float positive value: 3.402823E+38
Precision value: 6
Minimum float positive value: 1.175494E-38
Maximum float positive value: 3.402823E+38
Precision value: 6
« Previous Next »
0 Comments