Fundamentals of Computer Programming - Old Questions

3. Describe the four basic data types with example.

6 marks | Asked in 2073

 Data type in C refers to an extensive system used for declaring variable for function of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.

The Four basic data types are described below:

1.      Integer type (int):

  •      Integers are whole numbers.
  •      It requires 16 bit of storage i.e. 2 bytes.
  •      Three classes of integer: Integer(int)Short integer (short int) and Long integer (long int)


E.g. int a;    int x=5;

 

2. Floating point type (float):

  • Floating point type are fractional numbers.
  • A variable of float type requires 4 bytes and the range of values that can be stored in it, is 3.4e-38 to 3.4e+38.\\
  • Variable is defined as:

float a;

float x=23.7;

 

3. Character type (char):

  •      All single character used in programs belong to character type.
  •      The character data type holds exactly 8 bits (1 byte).
  •      The unsigned char has values between 0 and 255.
  •      The signed char has values from -128 to 127.
  •      Variable is declared as:

char var1= ‘h’;

            Here, var1 is a variable of type char which is storing a character ‘h’.

 

4. Double precision floating point type (double):

     i. Double precision:

  •          It reserves 8 bytes in memory.
  •          It represents fractional number of the range 1.7e-308 to 3.4e+308

   ii. Long double precision:

  •          It reserves 10 bytes in memory.
  •          It represents fractional numbers of the range 3.4e-4932 to 1.1e+4932