pow() function in C


The function pow() is used to calculate the power raised to the base value. It takes two arguments. It returns the power raised to the base value. It is declared in “math.h” header file.

Here is the syntax of pow() in C language,

double pow(double val1, double val2);

Here,

val1 − The base value whose power is to be calculated.

val2 − The power value.

Here is an example of pow() in C language,

Example

#include<stdio.h>
#include<math.h>
int main() {
   double x = 5.5;
   double y = 4.0;
   double p;
   p = pow(x, y);
   printf("The value : %lf", p);
   return 0;
}

Output

The value : 915.062500

On some online compilers, the following error may occur.

undefined reference to `pow'
error: ld returned 1 exit status

The above error occurs because we have added “math.h” header file, but haven’t linked the program to the following math library.

libm.a

Link the program with the above library, so that the call to function pow() is resolved.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements