C++ Standard Library C++ STL Library

C++ <cmath> - pow() Function



The C++ <cmath> pow() function returns the base raise to the power of exponent.

Syntax

double pow (double base, double exponent);
float pow (float base, float exponent);
long double pow (long double base, long double exponent);
double pow (double base, int exponent);
long double pow (long double base, int exponent);
double pow (double base, double exponent);
float pow (float base, float exponent);
long double pow (long double base, long double exponent);
//additional overloads 
double pow (Type1 base, Type2 exponent);                

Parameters

base Specify the base.
exponent Specify the exponent.

Return Value

Returns the base raise to the power of exponent.

Example:

In the example below, pow() function is used to calculate the base raised to the power of exponent.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  cout<<pow(2, 3)<<"\n";
  cout<<pow(2.3, 4)<<"\n"; 
  return 0;
}

The output of the above code will be:

8
27.9841

❮ C++ <cmath> Library