Datatypes


Built in datatypes :

  • C contains some built in datatypes also called basic datatypes or fundamental datatypes.

  • Built in datatypes may have several modifiers as per need in program .

  • The modifiers such as signed(depends on sign of value i.e. +ve or -ve) , unsigned(does not contains any sign , it is always positive) , long , short may be applied to characters and integers datatypes .
Datatype Range Size(in bytes)
char -128 to 127 1
int -31768 po 32767 2 or 4
float 3.4e-38 to 3.4e+38 4
double 1.7e-308 to 1.7e+308 8
unsigned char 0 to 255 1
signed char -128 to 127 1
unsigned int 0 to 65535 2
signed int -31768 po 32767 2
short int -31768 po 32767 2
unsigned short int 0 to 65535 2
signed short int -31768 po 32767 2
long int -2,147,483,648 to 2,147,483,647 4
signed long int -2,147,483,648 to 2,147,483,647 4
unsigned long int 0 to 4,294,967,295 4
long double 3.4E-4932 to 1.1E+4932 10

User defined datatypes :

  • We have user defined datatypes in C such as structure and union an enum.
  • The difference between structure and union is only of size allocation.

Struct

struct{
char name[6];
int x,y;
float z;
}

Here char need 1 byte ,int need 2 bytes twice and float requires 4 bytes. Therefore total memory required is 6+(2+2)+4=14 bytes .

Union :

union{
char name[6];
int x,y;
float z;
}

Here union takes biggest datatypes to store for shared datatypes. Therefore total memory required in union is 4 bytes.

Enumerated data type

  • The enumerated datatypes gives you an opportunity to invent your own datatype and define what value of this datatype can take.

  • for example one could create a datatype named as profession , which may have any variable such as labour , manager , teacher , doctor, etc.

  • The format of enum is given below
  • 
    enum profession
    {
    	doctor , labour , manager , teacher ;
    };
    enum profession person1 , person 2 ;
    
    

    Derived datatypes :

    • Arrays : Arrays are collection of elements of similar datatypes.
    • pointers : The declaration and initialisation of pointers are as follows ,
      int *p;
      p=&x;
      *p=5;

    • Print Page