Data types in C

Datatype define the type of data a variable can hold, for example an integer variable can hold integer data, a character type variable can hold character data etc.

Datatypes

Datatype classify into 3 types

  • Primary Datatype.
  • Derived Datatype.
  • User Defined Datatype.

Primary or Primitive Datatype

Primitive datatype contains:

short, int, long, float, double,and char.

int

It contains integer value.

float

It contains integer Decimal value.

char

It contains integer character.

Datatype Size (bytes) Range
char 1 -128 to 127 or 0 to 255
short 2 -32,768 to 32,767
int 4 -2,147,483,648 to 2,147,483,647
long 4 or 8 -9223372036854775808 to 9223372036854775807
unsigned char 1 0 to 255
unsigned short 2 0 to 65,535
unsigned int 4 0 to 4,294,967,295
unsigned long 4 or 8 0 to 18446744073709551615
float 4 ±3.40282347E+38
double 8 ±1.7976931348623157E+308
long double 8 or 16 ±1.1897314953572317650E+4932
void N/A N/A

Derived Datatype:

Derived data type is the aggregation of fundamental data type. character, integer, float, and void are fundamental data types. Pointers, arrays, structures and unions are derived data types.

Datatypes

User Defined Datatype

Those data types which are defined by the user as per his/her will are called user-defined data types.

Types of user define Datatype

  • Structure.
  • Union.
  • Enumration.

Structure

Structure is a user define datatype. the keyword of structure is 'struct'.

Union

Union is a user define datatype. the keyword of union is 'union'.

Enumration

Enumration is a user define datatype. the keyword of Enumration is 'enum'.