Using C Datatypes (with Examples)
Using C Datatypes (with Examples)
The Datatype defines the type of data being used.
The C language has 5 basic (primary or primitive) data types, they are:
- Character -
char - Integer -
int - Floating-point -
float - Double -
double - Void -
void
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 signed, unsigned, long, and short -
1. **char** Datatype
- The
chardatatype 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
chardatatype.
For example,
char status = 'Y';2. int Datatype
- The
intdatatype is used to store whole numbers. - Whole numbers are values without any decimal part or exponent part.
- The
intdatatype 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
intdata type, we can use suffixUoru, to tell the compiler that the value is forunsignedintdata type and suffixLorlfor alongintvalue.
3. float Datatype
- The
floatdata 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
floatvalue,
float x = 127.675;
// with suffix F or f
float y = 1000.5454F;4. double Datatype
The real numbers are big enough that they cannot be stored in float datatype, are stored as 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.










