# C ceil() function

## C ceil() function - Find integer

Syntax:

`double ceil(double x)`

The ceil() function is used to compute the smallest integer that is greater than or equal to x.

Parameters:

Name Description Required /Optional
x Floating-point value. Required

Return value from ceil()

• Returns the integer as a double value.

Example: ceil() function

The following example shows the usage of ceil() function.

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

int main(void)
{
double x, y, z;
x = 123.345;
y = 1.05;
z = -1.05;
printf("Before applying ceil():");
printf("\nx = %.3f ; y = %.2f ; z = %.2f\n", x, y, z);
x = ceil(123.345);
y = ceil(1.05);
z = ceil(-1.05);
printf("\n\nAfter applying ceil():");
printf("\nx = %.3f ; y = %.2f ; z = %.2f\n", x, y, z);
}
``````

Output:

```Before applying ceil():
x = 123.345 ; y = 1.05 ; z = -1.05

After applying ceil():
x = 124.000 ; y = 2.00 ; z = -1.00
```

C Programming Code Editor:

Previous C Programming: C sqrt()
Next C Programming: C fabs()

﻿

## C Programming: Tips of the Day

What's the point of const pointers?

const is a tool which you should use in pursuit of a very important C++ concept:

Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.

Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:

```void foo(int* ptr)
{
ptr = 0;// oops, I meant *ptr = 0
}
```

If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.

Ref : https://bit.ly/33Cdn3Q