int is integers, which is numbers with no decimal point.
char hold a maximum value of 255. Usually used to store characters in arrays.
float or double store values with decimal point.
Now, these values data types can be positive or negative. Example:-
unsigned int counter;
So now counter is a non negative integer value. If you want the variable counter to be able to store negative values, it would be defined as:-
signed int counter;
There is a limit to the value counter can hold. Below is the table for your reference of the maximum and minimum data type values.
| Type | Size in bytes | Range | 
| (unsigned)   char | 1 | 0 .. 255 | 
| signed   char | 1 | - 128 .. 127 | 
| (signed)   short (int) | 1 | - 128 .. 127 | 
| unsigned   short (int) | 1 | 0 .. 255 | 
| (signed)   int | 2 | -32768 .. 32767 | 
| unsigned   (int) | 2 | 0 .. 65535 | 
| (signed)   long (int) | 4 | -2147483648 .. 2147483647 | 
| unsigned   long (int) | 4 | 0 .. 4294967295 | 
| float | 4 | ±1.17549435082 * 10-38   ..   ±6.80564774407 * 1038 | 
| double | 4 | ±1.17549435082 * 10-38   .. ±6.80564774407 * 1038 | 
| long   double | 4 | ±1.17549435082 * 10-38   .. ±6.80564774407 * 1038 | 
So use the right data types and save memory. I will explain long and short in a later post.
 
 
 

No comments:
Post a Comment