C Data Types


Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that we use in our program. These datatypes have different storage capacities.

C language supports 2 different type of data types,


Primary data types

These are fundamental data types in C namely integer(int), floating(float), charater(char) and void.


Derived data types

Derived data types are like arrays, functions, stuctures and pointers. These are dicussed in detail later.

Primary data types in c

Integer type

Integers are used to store whole numbers.

Size and range of Integer type on 16-bit machine

TypeSize(bytes)Range
int or signed int2-32,768 to 32767
unsigned int20 to 65535
short int or signed short int1-128 to 127
long int or signed long int4-2,147,483,648 to 2,147,483,647
unsigned long int40 to 4,294,967,295

Example

#include <stdio.h>
#include <limits.h>

int main()
{
   printf("Storage size for int : %d \n", sizeof(int));
   
   return 0;
}
Output
Storage size for int : 4

Floating type

Floating types are used to store real numbers.

Size and range of Integer type on 16-bit machine

TypeSize(bytes)Range
Float43.4E-38 to 3.4E+38
double81.7E-308 to 1.7E+308
long double103.4E-4932 to 1.1E+4932

Example

#include <stdio.h>
#include <float.h>

int main()
{
   printf("Storage size for float : %d \n", sizeof(float));
   printf("Minimum float positive value: %E\n", FLT_MIN );
   printf("Maximum float positive value: %E\n", FLT_MAX );
   printf("Precision value: %d\n", FLT_DIG );
   
   return 0;
}
Output
Storage size for float : 4
Minimum float positive value: 1.175494E-38
Maximum float positive value: 3.402823E+38
Precision value: 6

Character type

Character types are used to store characters value.

Size and range of Integer type on 16-bit machine

TypeSize(bytes)Range
char or signed char1-128 to 127
unsigned char10 to 255

void type

The void type specifies that no value is available.

It is used in three kinds of situations:

Types Description
Function returns as voidThere are various functions in C which do not return value or you can say they return void. A function with no return value has the return type as void. For example void exit (int status);
Function arguments as voidThere are various functions in C which do not accept any parameter. A function with no parameter can accept as a void. For example, int rand(void);
Pointers to void A pointer of type void * represents the address of an object, but not its type. For example a memory allocation function void *malloc( size_t size ); returns a pointer to void which can be casted to any data type.

Share this article on