The pow() function returns the result of the first argument raised to the power of the second argument. This function is defined in the cmath header file.
In C++, pow(a, b) = ab.
Example
pow() Syntax
The syntax of the pow() function is:
pow(double base, double exponent);
pow() Parameters
The pow() function takes two parameters:
- base - the base value
- exponent - exponent of the base
pow() Return Value
The pow() function returns:
- the result of
baseexponent - 1.0 if
exponentis zero - 0.0 if
baseis zero
pow() Prototypes
The prototypes of pow() as defined in the cmath header file are:
double pow(double base, double exponent);
float pow(float base, float exponent);
long double pow(long double base, long double exponent);
// for other argument types
Promoted pow(Type1 base, Type2 exponent);
Since C++ 11,
- if any argument passed to
pow()islong double, the return typePromotedislong double - else, the return type
Promotedisdouble
Example 1: C++ pow()
Output
3.4 ^ 4.4 = 218.025
Example 2: pow() With Different Arguments
Output
4.4 ^ -3 = 0.0117393 -4 ^ 6 = 4096