C pow() Function

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

Definition

In C, pow() returns the base raised to an exponent. pow(2, 3) is 8.

You pass two double values, the base and the exponent, and both are required. The result is a double. Include <math.h>.

Syntax

Pass the base, then the exponent. Start with this call.

C
pow(2.0, 3.0);
CallWhat it does
pow(2.0, 3.0)Returns 8, because 2 × 2 × 2 is 8.

Include <math.h>. On GCC, link with -lm.

Library declarations
C
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);

Parameters

ParameterDescription
baseRequired. The number you raise.
exponentRequired. The power you raise it to.

Return Value

Return ValueDescription
base to the exponentA double. pow(2, 3) is 8.
NaNPossible when a negative base is raised to a fractional exponent.

C Examples

Example 1 — Common Powers

Compute a few everyday powers with integer exponents.

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

int main(void) {
    printf("pow(2, 3) = %.1f\n", pow(2.0, 3.0));
    printf("pow(5, 2) = %.1f\n", pow(5.0, 2.0));
    printf("pow(10, 0) = %.1f\n", pow(10.0, 0.0));

    return 0;
}

How It Works

  1. Include math.h. Declares pow; link with -lm on GCC.
  2. Cube and square. 2³ = 8 and 5² = 25.
  3. Any nonzero base to 0. pow(10, 0) is 1.
  4. Double results. Even whole answers come back as double.

Example 2 — Fractional and Negative Exponents

Fractional exponents act like roots. Negative exponents give reciprocals. Prefer sqrt when you only need a square root.

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

int main(void) {
    printf("pow(16, 0.5) = %.1f\n", pow(16.0, 0.5));
    printf("pow(8, 1.0/3.0) ≈ %.6f\n", pow(8.0, 1.0 / 3.0));
    printf("pow(2, -1) = %.1f\n", pow(2.0, -1.0));

    return 0;
}

How It Works

  1. Half power. pow(16, 0.5) is √16 = 4.
  2. One-third power. Approximates a cube root; prefer cbrt for negatives.
  3. Negative exponent. pow(2, -1) is 1 / 2.
  4. Float noise. Root results may print with tiny rounding error; that is normal for double.

Example 3 — Compound Growth

Use pow in the formula A = P × (1 + r)n.

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

int main(void) {
    double principal = 1000.0;
    double rate = 0.05;
    int years = 3;
    double amount = principal * pow(1.0 + rate, years);

    printf("principal = %.2f\n", principal);
    printf("after %d years = %.2f\n", years, amount);

    return 0;
}

How It Works

  1. Growth factor. Each year multiplies by 1.05.
  2. Raise to years. pow(1.05, 3) applies that factor three times.
  3. Scale by principal. Multiply by 1000 for the final amount.
  4. Money note. This is a math demo; real finance often uses cents or decimal types.

Frequently Asked Questions

pow() returns the base raised to an exponent. pow(2, 3) is 8.
Both are required. base is the number you raise, and exponent is the power.
A double. A negative base with a fractional exponent can return NaN.
Include <math.h>. On GCC, link with -lm.
Use sqrt() for square roots and cbrt() for cube roots, especially when the input can be negative.

Next: round()

Round a floating-point value to the nearest integer.

round() 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