C++ cmath pow() function
Example
Raise different numbers to different powers:
cout << pow(2.0f, 8.0f);
cout << pow(3.0f, 4.0f);
cout << pow(9.0, 0.5);
cout << pow(8.0, -1.0);
cout << pow(10.0f, -2.0f);
Try it Yourself »
Definition and Usage
The pow() function raises a number to the power of another number.
The pow() function is defined in the <cmath> header file.
Syntax
One of the following:
pow(double base, double exponent);
pow(float base, float exponent);
Parameter Values
| Parameter | Description |
|---|---|
| base |
Required. The base of the power operation. If this is an integer type then it will be treated as a double.
|
| exponent |
Required. The exponent of the power operation. If this is an integer type then it will be treated as a double.
|
Technical Details
| Returns: | A float value (if all the arguments are float) or double value (in any other case) representing the result of a power operation. |
|---|