Types of Variables
Data types
In the previous section, we explained variable declaration and usage.
I didn't explain much about types when declaring variables.
In the previous section, we explained that variables are declared using the following format.
A type name is an example of something to remember about the kind of numerical value.
In the previous section, we used int to store integers.
There are many other varieties of this type.
C allows you to work with various types of numbers.
And for each of those values, you need to store them using separate types of variables.
Sometimes, different kinds of numbers are referred to as data types.
The type of numerical data, differing in aspects such as the maximum number of digits and whether it's an integer or a real number.
In C, each type is given a separate name.
And it's often referred to as a so-and-so type.
I didn't explain much about types when declaring variables.
In the previous section, we explained that variables are declared using the following format.
Declare variables.
Type name variable name;
A type name is an example of something to remember about the kind of numerical value.
In the previous section, we used int to store integers.
There are many other varieties of this type.
C allows you to work with various types of numbers.
And for each of those values, you need to store them using separate types of variables.
Sometimes, different kinds of numbers are referred to as data types.
Keyword
【Data types】
The type of numerical data, differing in aspects such as the maximum number of digits and whether it's an integer or a real number.
In C, each type is given a separate name.
And it's often referred to as a so-and-so type.
Variables that store real numbers.
There aren't many types of data used in C.
For now, just remembering these two things will be enough.
The variable I just used was of type int.
Besides that, you can also use a variable of another type called double.
While an int data type stores integers, a double data type stores floating-point numbers.
These two are identical in how they're used, differing only in the type of numbers they store.
The following program demonstrates performing arithmetic operations using the double data type.
The results of this program are as follows:
Comparing it with the previous program, you're sure to find that the usage is exactly the same.
For now, just remembering these two things will be enough.
| Type Name | Numeric types |
|---|---|
| int | Integer |
| double | Real Number |
The variable I just used was of type int.
Besides that, you can also use a variable of another type called double.
While an int data type stores integers, a double data type stores floating-point numbers.
These two are identical in how they're used, differing only in the type of numbers they store.
The following program demonstrates performing arithmetic operations using the double data type.
Source code
#include <stdio.h>
int main(void)
{
double left, right;
left = 10;
right = 3;
printf("%f\n", left + right);
printf("%f\n", left - right);
printf("%f\n", left * right);
printf("%f\n", left / right);
return 0;
}
The results of this program are as follows:
Results
13.000000
7.000000
30.000000
3.333333
7.000000
30.000000
3.333333
Comparing it with the previous program, you're sure to find that the usage is exactly the same.
About This Site
Learning C language through suffering (Kushi C) isThis is the definitive introduction to the C language.
It systematically explains the basic functions of the C language.
The quality is equal to or higher than commercially available books.




