Data Types in C Language

In the C programming language, data types define the type of data that can be stored in variables. Each data type has a specific range of values and occupies a certain amount of memory. Understanding data types is crucial for effectively working with variables and performing operations on them. In this tutorial, we'll explore the basic data types in C and their characteristics, presented in a table format.

There are four types of data types in C language:

TypesData Types
Basic Data Typeint, char, float, double
Derived Data Typearray, pointer, structure, union
Enumeration Data Typeenum
Void Data Typevoid

Basic Data Types

Data TypeMemory Size (in bytes)Range (signed)Range (unsigned)
char1-128 to 1270 to 255
int2 or 4-32,768 to 32,767 (2 bytes)0 to 65,535 (2 bytes) or -2,147,483,648 to 2,147,483,647 (4 bytes)
short2-32,768 to 32,7670 to 65,535
long4 or 8-2,147,483,648 to 2,147,483,647 (4 bytes)0 to 4,294,967,295 (4 bytes) or -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (8 bytes)
float4N/AN/A
double8N/AN/A

Category Wise Basic Data Type in C

CategoryData TypeMemory Size (in bytes)Value Range
Integerchar1-128 to 127
unsigned char10 to 255
short2-32,768 to 32,767
unsigned short20 to 65,535
int2 or 4-32,768 to 32,767 (2 bytes) or
-2,147,483,648 to 2,147,483,647
(4 bytes)
unsigned int2 or 40 to 65,535 (2 bytes) or
0 to 4,294,967,295 (4 bytes)
long4 or 8-2,147,483,648 to 2,147,483,647
(4 bytes) or
-9,223,372,036,854,775,808 to
9,223,372,036,854,775,807 (8
bytes)
unsigned long4 or 80 to 4,294,967,295 (4 bytes) or
0 to 18,446,744,073,709,551,615
(8 bytes)
Floatingfloat41.2E-38 to 3.4E+38
Pointdouble82.3E-308 to 1.7E+308
long double10, 12, or 163.4E-4932 to 1.1E+4932
Characterchar1-128 to 127
unsigned char10 to 255
wchar_t2 or 40 to 65,535 (2 bytes) or
0 to 4,294,967,295 (4 bytes)
char16_t20 to 65,535
char32_t40 to 4,294,967,295
_Bool10 or 1

These are some of the commonly used data types in C. Each data type has its own memory size and range of values, which should be considered when selecting the appropriate type for your variables.

The char data type is used to store individual characters and occupies 1 byte of memory. It can represent both positive and negative values.

char Data Type Example:

The int data type is used for integers and can have different memory sizes depending on the platform (2 bytes or 4 bytes). It can represent both positive and negative values.

int Data Type Example:

The short data type is used for short integers and occupies 2 bytes of memory. It can represent both positive and negative values.

int Data Type Example:

The long data type is used for long integers and can have different memory sizes depending on the platform (4 bytes or 8 bytes). It can represent both positive and negative values.

long Data Type Example:

The float data type is used for single-precision floating-point numbers and occupies 4 bytes of memory. It is capable of representing fractional values.

float Data Type Example:

The double data type is used for double-precision floating-point numbers and occupies 8 bytes of memory. It provides higher precision compared to the float data type.

double Data Type Example:

It's important to note that the ranges mentioned in the table above are for signed data types. When using unsigned data types, the entire range becomes positive values starting from zero.

By understanding the characteristics of different data types, you can choose the most suitable type for your variables, ensuring efficient memory usage and appropriate value representation in your programs.

Understanding the data types in C and their properties is essential for effectively working with variables and performing operations on them. By selecting the appropriate data type, you can ensure accurate storage and manipulation of data in your C programs.