Float in C
Float is a data type that enables the user to declare variables and assign floating point values to the variable.
The syntax for declaring float variable
The data type is used to declare the numbers with decimal points. Its syntax is as follows:
You can also use the float keyword once to declare multiple floating point variables at once.
Parameters or Arguments
Now let us see examples to learn how to use the float in your C program.
Example 1: Declare the Variable
In the code below, we have used the float keyword to declare the roi variable in the program.
Example 2: Declare the Variable and assign the value to the variable
In the code below, we have declared the variable and assigned the value to the variable in a single statement. This reduces unnecessary lines of code.
Example 3: Declare Multiple Floating Point Variable in a single line
The user can also declare multiple variables in a single line using the datatype only once. To declare multiple variables in a single statement, the user must separate the variable names by commas (,).
Let us see an example to implement the statement in your code.
Example 4: Declaring multiple floating point variables and assigning the values to the variable in the same statement.
It is possible to declare different variables simultaneously until they have the same datatype. To declare floating point variables and assign the values to the variable, use the float keyword, followed by key=value pairs of the variable name and value, each separated by a comma (,).
Differentiate between float and double datatype in C Programming
There are two data types in C and C++ that allow users to take and return decimal point values in the system. These data types are float and double, and the user can use both these data types to represent such numbers.
Now the question arises why use two different data types for representing the same type of data and what is the difference between these two data types?