The different data types that we use in C programming are integer, short int, Signed and un signed char etc.
Data Types
Data type specifies the set of values and the type of data that can be stored in a variable. They allow the programmer to select the type appropriate to the needs of application.
The data types are as follows −
- Primary data types
- Derived data types
Let us understand primary data types.
Primary data types
‘C’ compilers support four fundamental data types. They are mentioned below −
- integer
- character
- Floating – point
- Double precision floating point
Integral data type
Integral data types are used to store whole numbers and characters. It is further classified into −
- Integer data type.
- Character data type.
Integer data type
This data type is used to store whole numbers. It has three classes of integer storage namely, short int, int and long int in both signed and unsigned forms.
Integer data type | |||
---|---|---|---|
Type | Size (in bytes) | Range | Control String |
short int (or) signed short int | 1 | -128 to 127 | %h |
Unsigned short int | 1 | 0 to 255 | %uh |
int (or) signed int | 4 | -32768 to 32767 | %d or %i |
unsigned int | 4 | 0 to 65535 | %u |
Long int (or) signed long int | 4 | -2147483648 to 2147483647 | %d |
Unsigned long int | 4 | 0 to 4294967295 | %lu |
Character data type
This data type is used to store characters. These characters are internally stored as integers. Each character has an equivalent ASCII value
For example: ‘A’ has ASCII value 65
Character Data Types | |||
---|---|---|---|
Type | size(in bytes) | Range | Control String |
Char(or) signed Char | 1 | -128 to 127 | %C |
unsigned Char | 1 | 0 to 255 | %c |
Floating - point Data types
- It is used to store real numbers (i.e., decimal point numbers).
- For 6 digits of accuracy, ‘float’ is used.
- For 12 digits of accuracy, ‘double' is used.
- For more than 12 digits of accuracy, ‘long double’ is used.
Floating Data Types | |||
---|---|---|---|
Type | size(in bytes) | Range | Control String |
float | 4 | 3.4E - 38 to 3.4 E + 38 | %f |
double | 8 | 1.7 E - 308 to 1.7 E + 308 | %lf |
long double | 16 | 3.4 E - 4932 to 1.1 E + 4932 | %Lf |
Example
Following is the C program to support primary data types −
#include<stdio.h> #include<limits.h> int main(){ printf("DATA TYPE\t\t RANGE\n"); printf("-----------\t\t---------\n"); printf("short min\t\t%d\n",SHRT_MIN); printf("short max int\t\t%d\n",SHRT_MAX); printf("int min\t\t\t%d\n",INT_MIN); printf("int max\t\t\t%d\n",INT_MAX); printf("Char min\t\t%d\n",CHAR_MIN); printf("Char max\t\t%d\n",CHAR_MAX); printf("long min\t\t%ld\n",LONG_MIN); printf("long max\t\t%ld\n",LONG_MAX); printf("unsigned char\t\t%u\n",UCHAR_MAX); printf("unsigned long\t\t%lu\n",ULONG_MAX); printf("unsigned int\t\t%u\n",UINT_MAX); printf("unsigned short\t\t%u\n",USHRT_MAX); }
Output
The output is as follows −
DATA TYPE RANGE ----------- --------- short min -32768 short max int 32767 int min -2147483648 int max 2147483647 Char min -128 Char max 127 long min -2147483648 long max 2147483647 unsigned char 255 unsigned long 4294967295 unsigned int 4294967295 unsigned short 65535