Data Types in C

In this post we will read about different data types in C.

Data types are used to define a variable for a specific information storage purpose. By assigning a data type to any variable or a value we define their type to the system. A size of variable, constant or array is defined by the data type to which it is assigned to. Different data types support different information type and different storage sizes.

Data types can be classified in to two categories:

  1. Basic Data Types
  2. Derived Data Types

Basic Data Types in C

A basic data type is one which constitutes the basic elements of a programming language. They are the bare minimum building blocks for any variable. Void, Integer, Double, Float and Character constitute the basic data type group.

Derived Data Types in C

A derived data type is derived from the basic data type and helps in storing bigger data chunks or storing data in a more organized manner i.e. by grouping or referencing. This subset consists of Array, Pointers, Structure, Union, Enum.

Void Data Type

  • It is a data type which has no value i.e. it’s empty.
  • It is used in pointers and functions.

Integer Data Type

  • It allows a variable to store numeric values.
  • ‘int’ is the keyword used to refer to integer data type.

Float Data Type

  • It allows variables to store values with decimals.
  • It is denoted by ‘float’ keyword only.

Double Data Type

  • Double also stores values with decimals but it has a more storage capacity than Float.
  • It is denoted by ‘double’ keyword.

Character Data Type

  • It allows a variable to store only one character like A or K or P.
  • ‘char’ keyword defines the character data type.

Array Data Type

  • It is a sequence of data items having homogeneous values.
  • It lays out adjacent memory locations to store values.

Pointers Data Type

  • Pointers help in accessing memory.
  • It is used to deal with memory addresses and referencing.

Structure Data Type

  • It brings variables of different types as a package under a single name.
  • ‘struct’ keyword is used to define structures.

Union Data Type

  • It allows storing various data types at same memory location.
  • A union with different members can be defined but only a single member can have a value at  a given point of time.

Enumeration Data Type

  • It is a special data type which consists of integral constants and each of them is assigned with a specific name.
  • “enum” keyword is used to define this data type.

Apart from these data types we have 5 modifiers in C:

  1. Short
  2. Long
  3. Signed
  4. Unsigned
  5. Long long

A summary table of different basic data types and the memory allocation for them.

Data Types Memory Size Range
char 1 byte −128 to 127
signed char 1 byte −128 to 127
unsigned char 1 byte 0 to 255
short 2 byte −32,768 to 32,767
signed short 2 byte −32,768 to 32,767
unsigned short 2 byte 0 to 65,535
int 2 byte −32,768 to 32,767
signed int 2 byte −32,768 to 32,767
unsigned int 2 byte 0 to 65,535
short int 2 byte −32,768 to 32,767
signed short int 2 byte −32,768 to 32,767
unsigned short int 2 byte 0 to 65,535
long int 4 byte -2,147,483,648 to 2,147,483,647
signed long int 4 byte -2,147,483,648 to 2,147,483,647
unsigned long int 4 byte 0 to 4,294,967,295
float 4 byte
double 8 byte
long double 10 byte

We will learn about each derived data types in detail in corresponding chapters.

Leave a Reply

Your email address will not be published. Required fields are marked *