C Data Types

In C programming, data types are declaration for variables. The variables are basically memory locations which hold some data. Basic data types include int, float, char, etc. To create a variable, first the data type is written followed by the variable name. For example,

int myVariable;

char Data Type:

The char data type can store a single character. It requires one byte of memory to store a character. Example,

char myCharacter = 'A';

int Data Type:

The int data type is used to store an integer. Example,

int var1 = -10;

float Data Type:

The float data type is used to store numbers with floating value. It is a 32-bit IEEE 754 single precision floating point number. It can store 7 digits after the decimal point. Example,

float e = 2.718;

double Data Type:

The double data type is similar to the float data type. It is a 64-bit IEEE 754 double precision floating point number. It can store 15 digits after the decimal point. Example,

double pi = 3.1415926535;

The following table shows the various types of data types in C language. Note, the specification may change according to the type of compiler. We have used MinGW GCC 4.8.1 32-bit Release compiler to generate these results.

Data Type Size Range Format Specifier
char 1 byte -128 to 127 %c
int 4 bytes -2,147,483,648 to 2,147,483,647 %d
unsigned int 4 bytes 0 to 4,294,967,295 %u
short int 2 bytes -32,768 to 32,767 %hd
unsigned short int 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
long long 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 %lli or %lld
unsigned long long 8 bytes 0 to 18,446,744,073,709,551,615 %llu
float 4 bytes 3.4E +/- 38 (7 digits) %f
double 8 bytes 1.7E +/- 308 (15 digits) %lf
long double 12 bytes 1.7E +/- 308 (15 digits) %Lf

Trending

C Programming

Remember to follow community guidelines and don't go off topic.