C cbrt() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, cbrt() returns the cube root of x. cbrt(8) is 2. A negative input is allowed and gives a negative result, so cbrt(-8) is -2.

You pass one double. The result is a double with the same sign as x. Include <math.h>.

Syntax

Pass any real number. Start with this call.

C
cbrt(8.0);
CallWhat it does
cbrt(8.0)Returns 2, because 2 × 2 × 2 is 8.

Include <math.h>. On GCC, link with -lm. Unlike sqrt(), a negative input is valid.

Library declarations
C
double cbrt(double x);
float cbrtf(float x);
long double cbrtl(long double x);

Parameters

ParameterDescription
xRequired. Any real double, including negatives.

Return Value

Return ValueDescription
Cube rootA double with the same sign as x.

C Examples

Example 1 — Common Cube Roots

Print cube roots for a few perfect cubes and zero.

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

int main(void) {
    printf("cbrt(0)  = %.1f\n", cbrt(0.0));
    printf("cbrt(8)  = %.1f\n", cbrt(8.0));
    printf("cbrt(27) = %.1f\n", cbrt(27.0));

    return 0;
}

How It Works

  1. Include math.h. Declares cbrt; link with -lm on GCC.
  2. Zero stays zero. cbrt(0) is 0.
  3. Perfect cubes. 2³ = 8 and 3³ = 27.
  4. Double results. Even exact roots come back as double.

Example 2 — Negative Numbers

Cube roots of negatives are negative. Prefer cbrt over pow(x, 1.0/3.0) here.

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

int main(void) {
    double x = -8.0;
    double r = cbrt(x);

    printf("cbrt(%.1f) = %.1f\n", x, r);
    printf("check: %.1f^3 = %.1f\n", r, r * r * r);

    return 0;
}

How It Works

  1. Pass a negative. cbrt stays in the reals.
  2. Sign matches. The root is -2.
  3. Verify by cubing. (-2)³ = -8.
  4. Avoid pow for this. pow(-8, 1.0/3.0) is often NaN on real-valued libm.

Example 3 — Edge Length from Volume

For a cube, edge length is the cube root of volume.

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

int main(void) {
    double volume = 64.0;
    double edge = cbrt(volume);

    printf("volume = %.1f\n", volume);
    printf("edge   = %.1f\n", edge);

    return 0;
}

How It Works

  1. Start with volume. A cube of volume 64.
  2. Take the cube root. That is the edge length.
  3. Check mentally. 4 × 4 × 4 = 64.
  4. Same idea as sqrt for squares. Use sqrt for area → side; cbrt for volume → edge.

Frequently Asked Questions

cbrt() returns the cube root of x. cbrt(8) is 2, and cbrt(-8) is -2.
x is required. Any real double is allowed, including negatives.
A double with the same sign as x.
Include <math.h>. On GCC, link with -lm.
Yes. A negative input returns a negative cube root.

Next: ceil()

Round a floating-point value up to the next integer.

ceil() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful