Range of Data Types in C
Range of Data Types in C Programming Language
Data types in C help the programmers, to work with different types of data in a program. Using which we can accept and print different types of data. These data types have a definite range of data, and we have to choose the datatype according to their range and our data set. Every datatype has a range according to ASCII values of the characters in C.
Range of various Data Types
As we have discussed above that there are many different data types in C, and every data type has a pre-defined range of data, under which it works, so we need to be smart while choosing a datatype in our program, below is a table which represents the different data-type, and their data range.
Name Of The Datatype | Range of Datatype |
Double | 2.3E-308 to 1.7E+308 |
Long Double | 3.4E-4932 to 1.1E+4932 |
Long | -9223372036854775808 to 9223372036854775807 |
Unsigned Long | 0 to 18446744073709551615 |
Float | .2E-38 to 3.4E+38 |
int | -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 |
unsigned int | 0 to 65,535 or 0 to 4,294,967,295 |
short | -32,768 to 32,767 |
unsigned short | 0 to 65,535 |
char | -128 to 127 or 0 to 255 |
signed char | -128 to 127 |
unsigned char | 0 to 255 |
Lets’s see a C program, for finding the range of the datatypes from the compiler itself. Yes, we can find out the range of the datatypes, from a C code also.
C code for finding the range of Datatypes :
#include<stdio.h> #include<stdlib.h> #include<limits.h> #include<float.h> int main() { printf("CHAR_BIT : %d\n", CHAR_BIT); printf("CHAR_MAX : %d\n", CHAR_MAX); printf("CHAR_MIN : %d\n", CHAR_MIN); printf("INT_MAX : %d\n", INT_MAX); printf("INT_MIN : %d\n", INT_MIN); printf("LONG_MAX : %ld\n", (long) LONG_MAX); printf("LONG_MIN : %ld\n", (long) LONG_MIN); printf("SCHAR_MAX : %d\n", SCHAR_MAX); printf("SCHAR_MIN : %d\n", SCHAR_MIN); printf("SHRT_MAX : %d\n", SHRT_MAX); printf("SHRT_MIN : %d\n", SHRT_MIN); printf("UCHAR_MAX : %d\n", UCHAR_MAX); printf("UINT_MAX : %u\n", (unsigned int) UINT_MAX); printf("ULONG_MAX : %lu\n", (unsigned long) ULONG_MAX); printf("USHRT_MAX : %d\n", (unsigned short) USHRT_MAX); return 0; }
Output :
CHAR_BIT : 8 CHAR_MAX : 128 CHAR_MIN : -127 INT_MAX : 2147483647 INT_MIN : -2147483648 LONG_MAX : 9223372036854775807 LONG_MIN : -9223372036854775808 SCHAR_MAX : 127 SCHAR_MIN : -128 SHRT_MAX : 32767 SHRT_MIN : -32768 UCHAR_MAX : 255 UINT_MAX : 4294967295 ULONG_MAX : 18446744073709551615 USHRT_MAX : 65535
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment