Facebook Page Twitter Page LinkedIn Page
× C Standard Library


The C <math.h> exp2() function returns 2 raised to the power of specified number, i.e., 2x.

Syntax

double exp2 (double x);
float exp2f (float x);
long double exp2l (long double x);

Parameters

x Specify the exponent of 2.

Return Value

Returns 2 raised to the power of specified number, i.e., 2x.

Example:

In the example below, exp2() function is used to calculate 2 raised to the power of specified number.

#include <stdio.h>
#include <math.h>
 
int main (){
  printf("%lf\n", exp2(2));
  printf("%lf\n", exp2(-2));
  printf("%lf\n", exp2(1.5));
  printf("%lf\n", exp2(-1.5));  
  return 0;
}

The output of the above code will be:

4.000000
0.250000
2.828427
0.353553

❮ C <math.h> Library

5