C language float type learning

There are two decimal types in C language, float and double;

float is called single-precision floating-point type, and double is called double-precision floating-point type;
float occupies 4 bytes, and double occupies 8 bytes;

Let's take a look at float;

#include <stdio.h>

int main() {
	float x = 52.55;
	float x2 = 52.55f;
	
    printf("%f\n", x);
    printf("%f\n", x2);
    return 0;
}

    The printf function uses %f to output the float type in decimal form;

    Numbers have a default type, for integers, the default is int type; for decimals, the default is double type;

    You can add a suffix to the number and specify the type manually. The suffix added to the float type is f or F;

In devcpp run as follows;

In VC6 run as follows;

  

Generally, you can use double directly for decimals;

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/131930363