C Data Types

In C programming, a data type or simply type is an attribute of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support common data types of real, integer and boolean.

In C language there are two types of data type:

  • Primitive data-type.(Primary data-type)
  • Non-primitive data-type.(Derived data-type)

Primitive data type

Primitive data type also known as Primary data types or pre-defined data types.

These data types are int, char, float, void.

Data type Size Range Description
char 1 byte -128 to +127 A character
int 2 or 4 byte-32,768 to 32,767 or
-2,147,483,648 to +2,147,483,647
An integer
float 4 byte 1.2E-38 to 3.4E+38Single precision floating point number
void 1 byte -128 to +127void type stores nothing

Character type(char):

It stores a single character and requires a single byte and can store 128 characters. In C programming language char keyword used to define the character type.

Integer data type (int):

As the name suggests, it is an integer data type which can only store integers. In C programming int keyword used to define integer type. Integer can any number. It means the integer can be zero, positive and negative value but cannot be a float or decimal value.

The size of the integer type is 2 or 4 bytes and it can store value upto 32,768 to 32,767 or -2,147,483,648 to +2,147,483,647.

Float type(float & double): 

It is used to store decimal numbers (numbers with floating point value) with single precision. In C programming language float or double keyword is used to define real numbers type.

The size of float is 4 bytes and size of double is 8 bytes. float can store value up to 1.2E-38 to 3.4E+38 whereas double store value up to 2.3E-308 to 1.7E+308.

void type(void):

As the name suggests, void internally does not store anything. They are used to define a function return type or a generic pointer.

Non Primitive data type

Non Primitive data type also known as Derived data types: These data types are: arrays, pointers, union, structures, etc.

Array:

An array is a collection of data or finite ordered collection of homogeneous data, stored in contiguous memory locations. Arrays are also referred to as structured data types.

Pointers:

In C language pointer is a variable the stores/points the address of another variable. Pointer is used to allocate memory dynamically. Pointer variable can be of type int, char, array function, or any other pointer.

Union:

C Union is also like structure, i.e. collection of different data types which are grouped together. Each element in a union is called member.

Structure: 

In Array, e can store data of one type only, but the structure is a variable that gives the facility of storing data of different data type in one variable. Structures are variables that have several parts; each part of the object can have different types. Each part of the structure is called a member of the structure.

Question-related to Datatype