Data types in C programming

Data type defines the type of the data that any variable will store. It is a system of declaring variables of different types. Data types are broadly categorized into three categories which are:
  1. Primitive/Pre-defined
  2. User defined
  3. Derived

Primitive/Pre-defined data type:

Primitive data types are the basic data types that are needed for performing general operations.
Example: int, char, float, double

User defined data type:

User defined data types are defined by user according to their need. They are defined or created from the primitive data types.
Example: struct, union, array, pointer

Derived data types:

Derived data types are basically the primitive data type with increased range of values it can store.
Example: short, long long int, double Below is a list of C data types:

Data type Size Range Format specifier
char 1 byte -127 to +127 %c
unsigned char 1 byte 0 to 255 %c
short 2 byte -32,767 to 32,767 %hi, %d, %i
unsigned short 2 byte 0 to 65,535 %hu, %d, %i
int 4 bytes -2,147,483,847 to +2,147,483,847 %d, %i, %u
unsigned int 4 bytes 0 to 4,294,967,295 %u
long 4 bytes -2,147,483,847 to +2,147,483,847 %d, %i, %u, %ld, %l, %li
unsigned long 4 bytes 0 to 4,294,967,295 %lu, %u
long long 8 bytes -9,223,372,036,854,775,807 to +9,223,372,036,854,775,807 %lli
unsigned long long 8 bytes 0 to 18,446,744,073,709,551,615 %llu
float 4 bytes 1.2E-38 to 3.4E+38 %f
double 8 bytes 2.3E-308 to 1.7E+308 %lf
long double 10 bytes 3.4E-4932 to 1.1E+4932 %Lf

Note: Size and range of types may vary on different platform. To check the size of any data type you can simple use


View list of all format specifiers in C.

View next C tutorial Hello World! Program in C.

Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< pre>< code >----Your Source Code---- < / code > < / pre > (Remove spaces from pre and code tags)

No comments:

Post a Comment