About Lesson
Double:
In C, the double data type is used to represent double-precision floating-point numbers. It provides a higher precision compared to the float data type. The double type typically occupies 8 bytes in memory.
Example:
#include <stdio.h>
int main() {
// Declaration and initialization of double variables
double value1 = 3.141592653589793;
double value2 = -2.71828;
double sum, product;// Performing arithmetic operations
sum = value1 + value2;
product = value1 * value2;// Displaying the values and results
printf(“Value 1: %fn”, value1);
printf(“Value 2: %fn”, value2);
printf(“Sum: %fn”, sum);
printf(“Product: %fn”, product);return 0;
}
Output:
Value 1: 3.141593
Value 2: -2.718280
Sum: 0.423313
Product: -8.539734
Explanation of code:
- #include <stdio.h>: This line includes the standard input-output library for functions like printf.
- int main(): The main function, where the program execution begins.
- double value1 = 3.141592653589793; and double value2 = -2.71828;: Declaration and initialization of double variables.
- double sum, product;: Declaration of two more double variables without initialization.
- sum = value1 + value2; and product = value1 * value2;: Performing arithmetic operations.
- printf(“Value 1: %fn”, value1);: Printing the value of value1 using the %f format specifier.
- Similarly, the values of value2, sum, and product are printed using printf.
- return 0;: Indicates successful program execution.