Data Types in C Language


Data type Definition

The data type supported in a language dictates the type of values which can be processed by the language.

C supports several different types of data, each of which may be represented differently within the computers memory.

Data types are means to identify the type of data and associated operations for handling it. Every variable in C has a data types.

Data types in C ?

There are three basic types of datatypes in C programming language.

1) Primitive Data types

Primitive data type is also known by different names such as Basic (or) simple or built in data types in C. Data types basically specify how we enter data into our programs and what type of data we enter.

Primitive data type can be augmented by using the data type qualifiers short, long, signed and unsigned.

The memory requirements for each data type may vary from one C compiler to another.

Given bellow are the primitive data types in c

Integer type

Integers are used to store whole numbers.

In C programming, 4 Bytes memory is allocated for Integer datatype. Size and range of Integer type on 16-bit machine is given below:

Type Size(bytes) Range
int or signed int 2 -32,768 to 32767
unsigned int 2 0 to 65535
short int or signed short int 1 -128 to 127
unsigned short int 1 0 to 255
long int or signed long int 4 -2,147,483,648 to 2,147,483,647
unsigned long int 4 0 to 4,294,967,295

Character type

Char is a data type which is used to represent individual characters. The char type will generally require one byte of memory. A char data type may have the identifiers signed and unsigned.

Character types are used to store characters value. Character data type allows a variable to store only one character.

Size and range of Integer type on 16-bit machine are given below:

Type Size(bytes) Range
char or signed char 1 -128 to 127
unsigned char 1 0 to 255

Floating point type

Floating point data type store numerical values with a fractional portion.

There are two types of floating data types named float and double. These may also have the qualifier long.

Long float may be equivalent to double and long double may be equivalent to double, or it may refer to a separate, "extralarge" double-precision data type requiring more than 8 bytes of memory.

Floating point numbers are essantially signed and it is used to store a real numbers.

Size and range of Integer type on 16-bit machine are given below:

Float43.4E-38 to 3.4E+38
double81.7E-308 to 1.7E+308
long double103.4E-4932 to 1.1E+4932

Double types

Double data type is also same as float data type which allows up-to 10 digits after decimal. The range for double datatype is from 1E–37 to 1E+37.

Double data types is also used for real numbers.

Float43.4E-38 to 3.4E+38
double81.7E-308 to 1.7E+308
long double103.4E-4932 to 1.1E+4932

Void data Types

This is usually used to specify the type of functions which returns nothing. We will get acquainted to this datatype as we start learning more advanced topics in C language, like functions, pointers etc.

Void is an empty data type that has no value. This can be used in functions and pointers.

2) Derived data types

The data types which are derived from fundamental data types are known as derived types.

It has basically three types of derived data types as given below.

  • Array
  • Pointers and
  • Functions
Data TypesDescription
ArraysArrays are sequences of data items having homogeneous values. They have adjacent memory locations to store values.
PointersThese are powerful C features which are used to access the memory and deal with their addresses.
FunctionsFunction pointers allow referencing functions with a particular signature.

To know about derived data type in c language read array, pointers and function in C.


3) User defined data types

Sometimes, the basic set of data types defined in the C language such as int, float etc. may be insufficient for your application. In such circumstances, we can create our own data types which are based on the standard ones.

  • Structure
  • Union
  • Enumerator and
  • Type of

C allows the feature called type definition which allows programmers to define their own identifiers that would represent an existing data type. There are three such types:

Data TypesDescription
StructureIt is a package of variables of different types under a single name. This is done to handle data efficiently. "struct" keyword is used to define a structure.
UnionThese allow storing various data types in the same memory location. Programmers can define a union with different members, but only a single member can contain a value at a given time.
EnumEnumeration is a special data type that consists of integral constants, and each of them is assigned with a specific name. "enum" keyword is used to define the enumerated data type.