Home > Article > Backend Development > Can int define decimals in C language?
no. int is an integer variable in C language. It can only store integers and cannot store decimals. If you need to store decimals, use floating-point data types (such as float, double).
Can int define decimals in C language?
Answer: No
Detailed explanation:
int is an integer variable in C language, used to store integers. It stores numbers in two's complement form and therefore can only represent integers. Unlike floating-point data types such as float and double, the int type cannot store values after the decimal point.
If you need to store decimals, you can use floating point data types such as float or double. These data types use floating point numbers to represent numbers and can store values after the decimal point.
Example:
<code class="c">int x = 10; // 整数 float y = 10.5; // 浮点数</code>
In the above example, x
is an integer variable that stores the integer 10. y
is a floating point variable that stores the floating point number 10.5.
The above is the detailed content of Can int define decimals in C language?. For more information, please follow other related articles on the PHP Chinese website!