# floor() in C++

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Topics Covered

## Overview

The floor in C++ is an inbuilt function that returns an integer value that is less than or equal to the argument. For example, the function floor(3.78) will return the integer value of 3 as an output. The floor in C++ is defined in the <Cmath> header file.

## What is floor() in C++

In C++, the floor function returns the largest integer, which is less than or equal to the given argument. The floor in C++ is defined in the cmath header file in C++.

### Explanation

The code discussed above passes a floating value of $2.7$ to the floor function as an argument. The largest integer which is less than or equal to $2.7$ is $2$. Thus the floor function returns an integer value of $2$ as the output.

## Syntax of the floor in C++

The syntax of the floor in C++ is as follows:

We need to pass the argument inside the $floor()$ function of which we want the floor value as an output. The argument can be a real number of any data type.

## Parameters of the floor in C++

The floor in C++, defined in the cmath header file, takes a floating-point number whose floor value is to be computed. The parameters can be of the type:

• double
• long double
• float

Note: When an integer value is passed inside the floor function as an argument, it is type cast into a double data type.

## Return Value of floor in C++

The floor in C++ returns an integer value that is less than or equal to the argument passed in the floor function.

## floor for Integer Values in C++

When an integer value is passed to the floor in C++ as an argument, the return value is equal to the argument itself.

## floor for Double and Float Values in C++

When a floating-point number is passed as an argument, the floor in C++ returns the largest integer that is less than or equal to the argument.

## Special Cases for floor in C++

Below are some of the special cases of the $floor$ in C++.

## Conclusion

• The $floor$ is an inbuilt function in C++ that returns an integer value that is less than or equal to the argument.
• Similar to the floor in C++, the $ceil()$ function in C++ returns an integer value greater than or equal to the argument.