C 语言中的 real
什么是 real?
real 是 C 语言中用于表示浮点数的数据类型,它是一个双精度浮点数。
特点:
立即学习“C语言免费学习笔记(深入)”;
占用 8 个字节的空间。 小数点后面可以拥有小数部分。 精度约为 15 位小数位。 范围约为 [-1.7976931348623157e+308, 1.7976931348623157e+308]。声明:
<code class="c">float variable_name; double variable_name;</code>float 会将变量声明为单精度浮点数,占用 4 个字节的空间,精度约为 6 位小数位。 double 会将变量声明为双精度浮点数,即 real。
示例:
<code class="c">int main() {
real x = 3.14159265; // 声明一个 real 类型变量并初始化为 π
printf("%f\n", x); // 输出 x 的值
return 0;
}</code>输出:
<code>3.141593</code>
