Using C Datatypes (with Examples)
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,
The range of value for character datatype is from -127 to 127.
As it's clear from the range, we can even use small integer values in the
char status = 'Y';
2. int Datatype
int datatype is used to store whole numbers.
Whole numbers 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
3. float Datatype
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 - To learn more about it, visit C datatypes guide for beginners
4. double Datatype
The real numbers are big enough that they cannot be stored in
float datatype, are stored as
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.