Introduction to data types in C?

Data types in C specifies the type of data that a variable can store inside it. There are several data types in C programming language. Every data type can be categorized into 4 main category of data types which are given bellow in the table.

Data types category Data types
Basic data type
int, long int, char, float, double
Derived data type
array, pointer, structure, union
Void data type
void
Enumeration data type
enum

Here we will discuss only about basic data types in C. Because other type of data type needs more discussion which we will provide in separate chapter. So, Don’t worry about that. Now, just try to understand basic data type.

Basic data types in C and it's classification

C programming language supports both signed and unsigned literals and the memory size may be change according to your system configuration. Let’s see some of the basic data types in C language. But remember there are more basic data types which we don’t need to take into account now. Because we can solve almost every problem using these data types given bellow.

Data type Keyword Size (Byte) Range Placeholder
Character
char
1
-127 to 128
%c
unsigned character
unsigned char
1
0 to 255
%c
integer
int
4
−2147483648 to 2147483647
%d
short integer
short int
2
−32,768 to 32,767
%hd
long integer
long int
4
-2,147,483,648 to 2,147,483,647
%l or %ld or %li
long long integer
long long int
8
-2^63 to 2^63-1
%lli or %lld
float
float
4
1.2E-38 to 3.4E+38
%f
double
double
8
2.3E-308 to 1.7E+308
%lf

Checking the size of your system's data type

You can easily check the size of integer of your computer by the following code given here. Let’s try this.

#include <stdio.h>
int main(){
    printf("Size of integer of your computer is = %d byte.\n", sizeof(int));
return 0;
}

Now, try to check the size of float data type of your computer by following lines of code.

#include <stdio.h>
int main(){
    printf("Size of float of your computer is = %d byte.\n", sizeof(float));
return 0;
}

Checking the size of character data type of your computer.

#include <stdio.h>
int main(){
    printf("Size of character of your computer is = %d byte.\n", sizeof(char));
return 0;
}

Checking the maximum or minimum value of a data types

You can also check the maximum and minimum limit of your system of any data type by the following code. Let’s try it yourself.

Checking maximum value of integer of your system.

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

int main(){
    printf("Maximum value of integer is = %d\n", INT_MAX);
return 0;
}

Checking minimum value of integer of your system.

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

int main(){
    printf("Minimum value of integer is = %d\n", INT_MIN);
return 0;
}

Checking maximum value of long integer of your system.

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

int main(){
    printf("Maximum value of long int is = %ld\n", LONG_MAX);
return 0;
}

Checking minimum value of long integer of your system.

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

int main(){
    printf("Minimum value of long int is = %ld\n", LONG_MIN);
return 0;
}

Now, try to check the limits and size of other data types in C. You can take help by seeing all the library function of header file limits.h which we have discussed more in our header file chapter.

Previous page:  Variables in C

Next pageKeywords in C