Data Types in C Language With Example

Data types defines the type and size of data, which a variable can store. In this tutorial, we will learn about different-different data types and their usage in C Language.

C language provides different-different data types. Each data type has different memory requirements and specific operations that can be done on it. Each variable in C has an associated data type, which user have to define while declaring the variable.

1. Basic Data Types:

There are four primary data types in C, which are int, char, float and double.

Basic Data Types in C

Data TypeFormat SpecifierSizeCapacity
char%c1 bytes-128 to +127
unsigned char%c1 bytes0 to 255
short%d2 bytes-32768 to +32767
unsigned short%d2 bytes0 to 65535
int%d or %i2 bytes-32768 to +32767
unsigned int%u2 bytes0 to 65535
long%ld4 bytes-2147483648 to +2147483647
unsigned long%lu4 bytes0 to 4294967295
float%f4 bytes3.4e-38 to 3.4e+38
double%lf8 bytes-1.7e-308 to +1.7e+308
long double%lf10 bytes-1.7e-4932 to +1.7e+4932

1. Int Data Type:

Integers are whole numbers that can be zero, positive, or negative, but do not have decimal values. For example: 0 , 1 , -1

In order to declare an integer variable, we can use int.

int age;

In this case, age is an integer variable.

In C programming, we can declare multiple variables at once. For example,

int id , age;

2. Char Data Type:

A char data type variable can only store one character. The char has a storage capacity of 1. It is the most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.

char ch = 'A';

3. Float Data Type:

The float data type is used to hold floating-point values in C programming. Decimal and exponential numbers are stored in C using the float keyword. It is used to hold decimal integers with single precision (numbers with floating point values). For example: 7.05 , 10.025 , 5.008

float salary;
float num = 2.5f;

4. Double Data Type:

In C, a double data type is used to hold decimal numbers with double precision (numbers with floating point values). It is used to define numeric values in C that contain numbers with decimal values. Double data type is essentially a precise data type that can carry 64 bits of decimal integers or floating points.

Since a double data type variable has high accuracy than a float, it is obvious that it takes up twice as much memory as the floating-point type. It may easily fit 16 to 17 digits after or before a decimal point.

double price;
double num = 12.293123;