Write a C program to display all datatypes ranges in tabular form


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
TypeSize (in bytes)RangeControl String
short int (or) signed short int1-128 to 127%h
Unsigned short int10 to 255%uh
int (or) signed int4-32768 to 32767%d or %i
unsigned int40 to 65535%u
Long int (or) signed long int4-2147483648 to 2147483647%d
Unsigned long int40 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
Typesize(in bytes)RangeControl String
Char(or) signed Char1-128 to 127%C
unsigned Char10 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
Typesize(in bytes)RangeControl String
float43.4E - 38 to 3.4 E + 38%f
double81.7 E - 308 to 1.7 E + 308%lf
long double163.4 E - 4932 to 1.1 E + 4932%Lf

Example

Following is the C program to support primary data types

 Live Demo

#include<stdio.h>
#include<limits.h>
int main(){
   printf("DATA TYPE\t\t RANGE
");    printf("-----------\t\t---------
");    printf("short min\t\t%d
",SHRT_MIN);    printf("short max int\t\t%d
",SHRT_MAX);    printf("int min\t\t\t%d
",INT_MIN);    printf("int max\t\t\t%d
",INT_MAX);    printf("Char min\t\t%d
",CHAR_MIN);    printf("Char max\t\t%d
",CHAR_MAX);    printf("long min\t\t%ld
",LONG_MIN);    printf("long max\t\t%ld
",LONG_MAX);    printf("unsigned char\t\t%u
",UCHAR_MAX);    printf("unsigned long\t\t%lu
",ULONG_MAX);    printf("unsigned int\t\t%u
",UINT_MAX);    printf("unsigned short\t\t%u
",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

Updated on: 13-Mar-2021

879 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements