Data Types in C

Data types are declarations for variables. It specifies the type and size of data that a variable can store. Each data type requires different amounts of memory and has some specific operations which can be performed over it.

There are the following data types in C

  1. Basic Data Type
  2. Derived Data Type
  3. Enumeration Data Type
  4. Void Data Type
Data TypesExample
Basic Data Typesint, char, float, double
Derived Data Typearray, pointer, structure, union
Enumeration Data Typeenum
Void Data Typevoid

Basic Data Types:-

It is also known as Primary Data Type. They are arithmetic types (integer-based and floating-point based). The memory size of the basic data types may change according to 32 or 64-bit operating system.

TypeMemory SizeFormat Specifier
intAtleast 2, usually 4%d
short int2%hd
unsigned intat least 2, usually 4%u
long intat least 4, usually 8%ld
long long int8%lld
unsigned long int4%lu
unsigned long long int8%llu
signed char1%c
unsigned char1%c
long doubleat least 10, usually 16%Lf

We can use the sizeof() operator to check the size of a variable on a particular platform.

C program to find the sizes of each of C’s data types in our system:

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
int main( void )
  printf( "Size of C data types:\n\n"                                 );
  printf( "Type               Bytes\n\n"                             );
  printf( "--------------------------------\n");
  printf( "char                 %lu\n" , sizeof( char )               );
  printf( "unsigned char        %lu\n" , sizeof( unsigned char )      );
  printf( "short                %lu\n" , sizeof( short )              );
  printf( "int                  %lu\n" , sizeof( int )                );
  printf( "unsigned             %lu\n" , sizeof( unsigned )           );
  printf( "long                 %lu\n" , sizeof( long )               );
  printf( "unsigned long        %lu\n" , sizeof( unsigned long )      );
  printf( "long long            %lu\n" , sizeof( long long )          );
  printf( "int64_t              %lu\n" , sizeof( int64_t )            );
  printf( "unsigned long long   %lu\n" , sizeof( unsigned long long ) );
  printf( "float                %lu\n" , sizeof( float )              );
  printf( "double               %lu\n" , sizeof( double )             );
  printf( "long double          %lu\n" , sizeof( long double )        );
  printf( "\n" );
return 0;

int:- Integers are whole numbers that can have both zero, positive and negative values but no decimal values.

** The keyword unsigned uses to store all the value of the number and always positive or Zero.

int a = 5;

Char:- It is used for declaring character type variables and stores a single character.

char i = u;

float:- It is used to store decimal numbers with single precision.

Double:- It is used to store decimal numbers with double precision.

Void Data Type:-

It means nothing or no value available. If a function is not returning anything, its return type should be void.

** We cannot create variables of void data type.

Derived Data Types:-

Data types that are derived from fundamental data types are derived types.

Enumerated Data Types:-

It can only assign certain discrete integer values throughout the program.