Data Types in C

In some of our tutorials in the beginning, I told you about the three primary data types which are used in C language. Today I will introduce you to some variations in these primary data types in C. We can make unlimited data types as per our requirement in C. So C language is quite rich in data types.

Data Types in C

The primary data types which we have used till now has some limits. For example, we can only store values in the range of –32768 to 32767 for an int data type. Remember this range is for 16 bit compiler Turbo C. For 32 bit compiler like VC++ this range is  –2147483648 to +2147483647. You can’t store more values which exceed this limit in int data type. To overcome those limits we have to use some extra keywords like unsigned, signed etc.

What are 16 bit and 32 bit compilers?
Turbo C is a 16 bit compiler. After converting the C code into machine language, it will target that code to run on 16 bit processors like intel 8086.

On the other hand VC++ is a 32 bit compiler. It will target to run the code on 32 bit processors like intel Pentium processors.

Data Types in C

short and long int

As I said earlier C language provides variation in its primary data types. short and long are such variations of integer data type. As its name suggests long has bigger range than int.

Note: Here short and long are both keywords.

The range of both short and long are given below.

Range of long is -2147483648  to 2147483647.
Range of short is -32,768 to +32,767

signed and unsigned int

Generally it happened when we are confirmed that the value will not be negative in any case. So to utilize those conditions efficiently we often use unsigned int. With the use of unsigned keyword the range of int data type shifts from negative to positive.

New range will be 0 to 65535

By default normal int is also called signed int.

signed and unsigned char

Range of normal char is -128 to +127. You must have known that char data type always stores the ASCII value of character. Many times we emerge in a condition when we have print or access the ASCII character who value is more than +127. So in that case we generally use unsigned char. Similar to int it also makes the range almost twice. Both signed and unsigned char occupies 1 byte in memory.

New range will be 0 to 255

float and double

float variable occupies 4 bytes in memory and it also provides a good range to store values in it. It gives the range of -3.4e38 to +3.4e38. 

If you want to increase this limit then you can also use double data type. It takes 8 bytes in the memory and it also provided a very big range to store values. Its range is -1.7e4932 to +1.7e4932.

Data Types in C

Declaration of all data types

Given below are declarations of all the data types which we have learned so far.

int a;
unsigned int b;
long int c;
short int d;
unsigned short int e;
unsigned long int f;
char g;
unsigned char f;
float g;
double h;

1 thought on “Data Types in C”

Leave a Comment

Your email address will not be published. Required fields are marked *