Primitive Data Types in C Programming

1. What is data type in C

Data type specifies what type of data a variable can hold.

There are four category of data type in C language. 

They are as follows:

Types Data Types
Basic (Primitive) data types int, char, float, double
Enumeration data type Enum
Derived data type pointer, array, structure, union
Void data type void

2. Primitive Data Types In C Language

There are two types of qualifiers are used with primitive data types

  1. Size Qualifier – short, long
  2. Sign Qualifier- signed, unsigned

Size qualifier specifies the size and range of data type short qualifier is used to store less amount of data compared to long qualifier.

Sign qualifier specifies whether a data type can store only positive value or positive and negative both.

By default a data type is signed qualifier.

Size of primitive data type depends on computer system and word size.

So our data type may vary with others.

If you want to check data size of int, char, float double you can use sizeof operator.

Example: How to find size of data types in c language.

Above Program shows the size of int, size of short, size of long, size of char, size of float, size of double data types in C. Similar way you can find size of all data types in C.

Following are details of data types with format specifier in c, range of data types in c.

1 Integer Data Type

Integer data ( example 1,2,3,4,5,6, ….. etc. ) is stored in int ,short and long data type.

Type Storage size Value range Format Specifier
int 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 %d or %i
unsigned int 4 bytes 0 to 65,535 or 0 to 4,294,967,295 %u
short 2 bytes -32,768 to 32,767 %hd
unsigned short 2 bytes 0 to 65,535 %hu
long 4 bytes -2,147,483,648 to 2,147,483,647 %ld
unsigned long 4 bytes 0 to 4,294,967,295 %lu

Example: Addition of integer number.

Output

Note: Here %i is a format specifier which is used to print integer value.

2. Character Data Type

Character data ( example ‘a’ , ‘b’ , ‘f’, ….. etc. ) is stored in “char” data type.

Type Storage size Value range Format Specifier
unsigned char 1 byte 0 to 255 %c
signed char 1 byte -128 to 127 %c

Example: Declare and initialize character variable.

Output

3. Float and Double Data Types

Floating point value (example  11.23, 333.3330 etc. ) can be stored in data type float and double.

Small floating value can be stored in float and large floating stored in double. 

Type Storage size Value range Format Specifier Precision
float 4 byte 1.2E-38 to 3.4E+38 %f ,%e or %E for scientific notation 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 %lf 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 %Lf 19 decimal places

Example: Declare and initialize float & double variable.

Output: