Learn C Programming
For the overview, history and character-set of C programming language click here.
Now in this post we will learn about the different types of data types, their size and range in C programming Language.
A C language programmer has to tell the system earlier about the type of number or character he is going to use in his program. These are known as ‘data types’. There are many data types in C language. A C programmer has to use appropriate data type as per the requirements.
C Language data types can be broadly classified as :
- Primary data type
- Derived data type
- User-defined data type
Primary Data Type
The following fundamental data types are accepted by the C Compilers :
|3. Floating Point||float|
|4. Double Precision floating point||double|
The size and range of each data type is given in the table below:
|DATA TYPE||RANGE OF VALUES|
|char||-128 to 127|
|Int||-32768 to 32767|
|float||3.4 e-38 to 3.4 e+38|
|double||1.7 e-308 to 1.7 e+308|
Now let us study the different types of data types in C Programming Language in detail:
Integers are whole numbers with machine dependent range of values. A good programming language should support the programmer by giving control on a range of numbers and storage space to the programmer. C has 3 Classes of integer storage named as short int, int and long int. All of these data types have their signed and unsigned forms. A short int requires half of the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number the long and unsigned integers are used to declare a long range of values.
Floating point types:
Floating point numbers represents a real number with 6 digits of Precision. Floating point numbers are denoted by the keyword ‘float’. When the accuracy of the floating point number becomes insufficient, we can use the double to define the number with more accuracy and precision. The double datatype is same as float datatype but provides good precision than float datatype. To extend the Precision more we can use long double which consumes 80 bits of memory space.
Using void data type, we can specify the type of a function. It is a good practice to use void datatype to those functions that does not return any values to the calling function.
A single character can be defined as a defined character type of data. Characters are usually stored in 8 bits of internal storage. The qualifiers signed or unsigned can be explicitly applied to char. Unsigned characters have values ranging between 0 and 255, signed characters have values from -128 to 127.
Size and range of Data Types on 16 bit machine.
|Char or Signed Char||8||-128 to 127|
|Unsigned Char||8||0 to 255|
|Int or Signed Int||16||-32768 to 32767|
|Unsigned Int||16||0 to 65535|
|Short Int or Signed Short Int||8||-128 to 127|
|Unsigned Short Int||8||0 to 255|
|Long Int or Signed Long Int||32||-2147483648 to 2147483647|
|Unsigned Long Int||32||0 to 4294967295|
|Float||32||3.4 e-38 to 3.4 e+38|
|Double||64||1.7 e-308 to 1.7 e+308|
|Long Double||80||3.4 e-4932 to 3.4 e+4932|
Some of the examples are:
int number, salary;
long double average, mean;