Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

pow — exponentiation

The pow function from <math.h> computes x raised to y, accepting and returning double. Learn its syntax and its domain and range limitations.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <math.h>
double pow(double x, double y);

pow(x, y) from <math.h> computes the power with base x and exponent y. Both parameters and the result have type double; the exponent need not be integral.

A finite negative base with a finite nonintegral exponent causes a domain error. A domain error is permitted for pow(0.0, 0.0); zero with a negative exponent may cause a domain or pole error. Extreme arguments can cause a range error.

The example computes pow(2.0, 3.0) and prints the result without decimal places. A floating-point result does not generally guarantee exact integer arithmetic.

Examples

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

int main(void)
{
    double base = 2.0;
    double exponent = 3.0;
    double result = pow(base, exponent);

    printf("%.0f\n", result);
    return 0;
}

Result

8

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources