C pow() function

C pow() function - Compute power


double pow(double x, double y)

The pow() function is used to calculate the value of x to the power of y.


Name Description Required /Optional
x Floating point base value. Required
y Floating point power value. Required

Return value from pow()

  • Returns the value 1 if y is 0.
  • Returns 0 if x is 0 and y is negative.
  • Returns 0 if both x and y are 0, or if x is negative and y is not an integer.

Example: pow() function

The following example shows the usage of pow() function.

#include <math.h>
#include <stdio.h> 
int main(void)
   double x, y, z;
   x = 2.0;
   y = 4.0;
   z = pow(x,y); 
   printf("%lf to the power of %lf is %lf\n", x, y, z);
   x = 2.2;
   y = 3.2;
   z = pow(x,y); 
   printf("\n%lf to the power of %lf is %lf\n", x, y, z);


2.000000 to the power of 4.000000 is 16.000000

2.200000 to the power of 3.200000 is 12.466731

C Programming Code Editor:

Previous C Programming: C modf()
Next C Programming: C sqrt()

Follow us on Facebook and Twitter for latest update.

C Programming: Tips of the Day

What's the point of const pointers?

const is a tool which you should use in pursuit of a very important C++ concept:

Find bugs at compile-time, rather than run-time, by getting the compiler to enforce what you mean.

Even though it does not change the functionality, adding const generates a compiler error when you're doing things you didn't mean to do. Imagine the following typo:

void foo(int* ptr)
    ptr = 0;// oops, I meant *ptr = 0

If you use int* const, this would generate a compiler error because you're changing the value to ptr. Adding restrictions via syntax is a good thing in general. Just don't take it too far -- the example you gave is a case where most people don't bother using const.

Ref : https://bit.ly/33Cdn3Q