The Datatype defines the type of data being used. We have covered C datatypes in detail in the previous tutorial.
The C language has 5 basic (primary or primitive) data types, they are:
Let's learn about each one of them one by one.
To learn about the size of data types, range of values for datatypes, and various type modifiers like
short - Visit C datatypes in detail
char datatype refers to character values, enclosed in single quotes, with a range of -127 to 127.
As it's clear from the range, we can even use small integer values in the
char status = 'Y';
int datatype is used to store whole numbers, which are values without any decimal part or exponent part.
int datatype can store decimal (base 10), octal (base 8), and hexadecimal (base 16) values.
// simple int value int a = 100; // negative value a = -100; // unsigned int value - with suffix U or u int x = 1000U; // long int value long int long_val = 3500L;
With the value of
int data type, we can use suffix
u, to tell the compiler that the value is for
int data type and suffix
l for a
Learn more about type identifiers(
short) and how they change the primary datatypes when used with them - Visit C datatypes guide for beginners
float data type is used to store real numbers which may have a decimal (fraction) part or an exponential part. It is a single-precision number.
Let's see some examples for
float x = 127.675; // with suffix F or f float y = 1000.5454F;
int datatype, the
float can also be used with type modifiers - Learn more about it, visit C datatypes guide for beginners
The real numbers which are big enough that they cannot be stored in
float datatype, is stored as a
double datatype. It is a double-precision number. A double datatype value can hold above 15 to 17 digits before the decimal point and 15 to 17 digits after the decimal point.
Here is an example,
double x = 424455236424564.24663224663322;
We should only use the
double datatype when we need such large numbers, otherwise not, because using
double datatype makes the program slow.
In this tutorial, we saw some examples for different data types available in the C language. To understand about the C data types in detail, visit C datatypes guide for beginners .