DATA TYPES IN C



C language is a bit rich in terms of data types. We have a lot of data types. But we must first define what a data type is. To understand it in a basic form, think of data types as a set of operations that can be performed on those values. Some of them are-


int (integer) , short int(short int) , long int (Long integer),long long int(Long Long integer)


Int is the most basic data type in C language.A common mistake is to learn the size of data types. Actually the size of data types depend on your system and not the language you use, In a 64 bit architecture, generally an int is of 4 bytes, a short int is of 2 bytes, a long int is of 4 or 8 bytes, and a long long int is of 8 bytes. The general rule to remember is, a short int cannot be larger than an int. An int cannot be larger than a long int. A long int cannot be larger than an long long int.
So let us write some codes to see the size of these data types in the system



The range of values that these data types can store is -2^(sizeof(data types)-1) to +2^(sizeof(data types)-1)-1. The symbol ^ stands for power.
The values that they store is integer. eg -2, -467838, 0, 478229,10,4 etc


float(Float), double(Double),long double(Long double)


They are used to store large data values. They are also used to store fractional values. But they have precision problem. To understand this, let us look at their sized.



Now it is common sense to understand why they loose precision. The size of float is also 4 bytes, but it can store larger values . This is by making compromise with the precision. You will learn about it more in your computer architecture classes.


char (Character)


It is used to store a single character.


This was just a little introduction to data types to get you started. For reference visit

Data types 1

Data types 2