# What Is Real Data Type in C?

//

Scott Campbell

What Is Real Data Type in C?

The real data type in the C programming language is used to represent numbers with decimal points. It is commonly used when precision is required, such as in scientific calculations or financial applications.

In C, there are two main types of real data types: float and double.

## Floating-Point Numbers in C

The float data type is used to store single-precision floating-point numbers. It occupies 4 bytes of memory and can represent numbers with a precision of about 6 decimal places.

Here’s an example of declaring a float variable in C:

``````
float pi = 3.14159;
``````

In the above example, the variable “pi” is declared as a float and assigned the value of 3.14159.

## Double-Precision Numbers in C

The double data type is used to store double-precision floating-point numbers. It occupies 8 bytes of memory and can represent numbers with a precision of about 15 decimal places.

Here’s an example of declaring a double variable in C:

``````
double distance = 12345.6789;
``````

In the above example, the variable “distance” is declared as a double and assigned the value of 12345.6789.

## Differences Between float and double Data Types

The main difference between float and double data types lies in their precision. Floats have a lower precision compared to doubles, which means they can represent a smaller range of values with less accuracy.

Doubles, on the other hand, have a higher precision and can represent a wider range of values with greater accuracy.

Additionally, doubles require more memory compared to floats because they occupy 8 bytes instead of 4. Therefore, if memory usage is a concern and high precision is not required, using float data types can be more efficient.

## Summary

• The real data type in C is used to represent numbers with decimal points.
• There are two main types of real data types in C: float and double.
• Floats have lower precision and occupy 4 bytes of memory.
• Doubles have higher precision and occupy 8 bytes of memory.

In conclusion, the real data type in C provides a way to handle numbers with decimal points. By understanding the differences between float and double data types, you can choose the appropriate one based on your specific requirements for precision and memory usage.