# What Is Double Data Type in C Example?

//

Angela Bailey

In C programming, the double data type is used to store floating-point numbers with double precision. It can hold larger and more accurate decimal values compared to the float data type. The double keyword is used to declare variables of double data type in C.

## Syntax:

The syntax for declaring a double variable in C is:

``````
double variable_name;
``````

## Example:

Let’s consider an example to understand the usage of the double data type in C:

``````
#include <stdio.h>

int main() {
double num1 = 3.14159;
double num2 = 2.71828;

printf("The value of num1 is %f\n", num1);
printf("The value of num2 is %f\n", num2);

return 0;
}
``````

In this example, we have declared two variables, num1 and num2, of the double data type and assigned them with floating-point values. We then print their values using the printf function.

### Output:

``````
The value of num1 is 3.141590
The value of num2 is 2.718280
``````

The output displays the values of num1 and num2, which are printed with their full precision due to the use of the %f format specifier.

## Precision Specifiers:

By default, the %f format specifier prints six decimal places. However, you can specify the precision by using the dot (.) followed by a number inside the format specifier.

For example:

``````
printf("The value of num1 with 2 decimal places is %.2f\n", num1);
``````

### Output:

``````
The value of num1 with 2 decimal places is 3.14
``````

In this case, the value of num1 is printed with only two decimal places.

## Limits of Double Data Type:

The double data type in C has a higher range and precision compared to the float data type. It can hold values ranging from approximately ±5.0 × 10^-324 to ±1.7 × 10^308.

## Conclusion:

The double data type in C is used to store floating-point numbers with double precision. It provides greater range and accuracy compared to the float data type. By specifying precision specifiers, you can control the number of decimal places when printing double values.

I hope this article helps you understand the concept of the double data type in C programming!