Math Pow Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Pow Function

Math Pow Function

BLUF: Mastering Math Pow Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Pow Function

C++ is renowned for its efficiency. Learn how Math Pow Function enables low-level control and high-performance computing in the tutorial below.

C++ Math pow

This function is utilized to calculate the exponentiation of a specified numerical value.

Consider a base 'b' and exponent 'e'.

Syntax

Its syntax would be :

Example

double pow(double b, double e);
float pow(float b, float e);
long double pow(long double b, long double e);
promoted pow(type1  b, type2 e);

Note: If any argument is of long double type, then the return type is promoted to long double. If not, then the return type is promoted to double.

Parameter

'b' represents the numerical value for which the exponentiation is to be determined.

e : 'e' is the exponent.

Return value

It returns the base 'b'raised to the power 'e'.

Example 1

Let's consider a basic scenario where both the base and exponent are of integer data type.

Example

#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int base=4;
  int exponent=2;
  int power=pow(base,exponent);
  std::cout << "Power of a given number is :" <<power;
  return 0;
}

Output:

Output

Power of a given number is :16

Example 2

Let's consider an instance where the base is of type float and the exponent is of type integer.

Example

#include <iostream>
#include<cmath>
using namespace std;
int main()
{
   int base=4.5;
  int exponent=3;
  int power=pow(base,exponent);
  std::cout << "Power of a given number is :" <<power;
  return 0;
}

Output:

Output

Power of a given number is :64

Example 3

Let's examine a basic scenario where both the base and exponent are of the float data type.

Example

#include <iostream>
#include<cmath>
using namespace std;
int main()
{
   int base=2.5;
  int exponent=2.5;
  int power=pow(base,exponent);
  std::cout << "Power of a given number is :" <<power;
  return 0;
}

Output:

Output

Power of a given number is :4

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience