C++ ceil()

The ceil() function in C++ returns the smallest possible integer value which is greater than or equal to the given argument.

It is defined in the cmath header file.

Example


ceil() Syntax

The syntax of the ceil() function is:

ceil(double num);

ceil() Parameters

The ceil() function takes the following parameter:

  • num - floating-point number whose ceiling value is to be computed

ceil() Return Value

The ceil() function returns:

  • the smallest possible integer value which is greater than or equal to num

ceil() Prototypes

The prototypes for ceil() as defined in the cmath header file are:

double ceil(double num);

float ceil(float num);

long double ceil(long double num);

// for integral types
double ceil(T num);

Example 1: C++ ceil()

Output

Ceil of 10.25 = 11

Example 2: C++ ceil() for Integral Types

Output

Ceil of 15 = 15

We will always get the same result for integral types. So this function is not used with integral types in practice.