How are float and double used in the C language?
In C language, float and double can be used to declare floating point type variables.
Float: The float type in the C language is a single-precision floating-point type that can store 6 significant digits and occupies 4 bytes of memory space. For example:
float num1 = 3.14;
The double type in C language is a double-precision floating point type that can store 15 significant digits and occupies 8 bytes of memory space. For example:
double num2 = 3.14159265359;
When using it, you can assign the value directly to a variable, or you can obtain a floating point value from user input using the scanf function.
float num1;
double num2;
num1 = 3.14;
num2 = 3.14159265359;
scanf("%f", &num1);
scanf("%lf", &num2);
It should be noted that when assigning or inputting double type variables, the %lf formatting character should be used instead of %f.