Size and Limits of Datatypes in C Language

Spread the love

Size-and-limits-of-datatypes-in-programming-language

Program Introduction:

In this article, We are going to write a program to calculate the size and limits of Datatypes in C programming.

The Limits of datatype mean, The Minimum allowed value and Maximum allowed value for a given datatype.

Example Size and limits of datatypes in C:

Let’s take character datatype. The size of character datatype is one ( 1 ) Byte.

And Limits of character datatype are Maximum available value is 127 and the Minimum value is -128.

So similar way we need to calculate the size and minimum and maximum limit of all datatypes of c programming language

Size and Limits of Datatypes in C Programming:

We are going to use the built-in sizeof operator to calculate the size of each datatype.

We calculate the Maximum limit and Minimum limit of a datatype using the C programming language limits.hlibrary.

The limits.hlibrary contains the Macros with all available variables Minimum limit and Maximum Limit.

For Example, To get the minimum value of the Integer variable, You first need to include the limits.h Library to your program. Then use the Macros INT_MINand INT_MAX of climit.h library. The INT_MINMacro provides the Minimum allowed integer value and The INT_MAX contains the Maximum allowed Integer value.

Similarly, We can calculate the Minimum value and Maximum value of all available datatypes of C Language.

Program: Size and Limits ( Minimum and Max ) of all datatypes in C:

We are using the climit.h library for getting the limits

In the above program, We calculated Min and Max of all datatypes. We also displaying the precision of all floating point datatypes like float, double, and Long double.

Program Output:

We are compiling the program using the gcc compiler.

Here is my original output.

size-and-limits-of-datatypes-in-c-programming-language

The Size and Min, Max Values of all Datatypes

Here is the summary of above output.

DatatypeSizeMinimum ValueMaximum Value
Character ( char)
1-128127
Unsigned Character11255
Short Integer ( short)2-3276832767
Unsigned Short Int2165535
Integer ( int )4-21474836482147483647
Unsigned Integer414294967295
Long Integer ( long )8-92233720368547758089223372036854775807
Unsigned Long Int8118446744073709551615
Float41.175494e-383.402823e+38
Double82.225074e-3081.797693e+308
Long Double163.362103e-49321.189731e+4932

Conclusion:

In this article, We have discussed the sizes of all datatypes in the C Language. We also looked into the maximum allowed value and minimum limit of all C language datatypes like integer, float, and characters, etc. We also looked at the precision of floating-point datatypes.

Related Reading:

Venkat

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

3 Responses

  1. May 31, 2021

    […] Size and Limits of Datatypes in C Language – SillyCodes […]

  2. May 31, 2021

    […] Size and Ranges (Limits) of all Datatypes […]

  3. July 6, 2021

    […] Size and Limits of Datatypes in C Language – SillyCodes […]

Leave a Reply