C exp() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, exp() returns e raised to the power x. exp(0) is 1, and exp(1) is about 2.718.

You pass one double. The result is a positive double. Include <math.h>.

Syntax

Pass the exponent. Start with this call.

C
exp(1.0);
CallWhat it does
exp(1.0)Returns e, about 2.718.

Include <math.h>. On GCC, link with -lm.

Library declarations
C
double exp(double x);
float expf(float x);
long double expl(long double x);

Parameters

ParameterDescription
xRequired. The exponent.

Return Value

Return ValueDescription
e to the power xA positive double. exp(0) is 1.

C Examples

Example 1 — Basic Exponential Values

Print exp(0), exp(1), and exp(2).

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("exp(0) = %.6f\n", exp(0.0));
    printf("exp(1) = %.6f\n", exp(1.0));
    printf("exp(2) = %.6f\n", exp(2.0));
    return 0;
}

How It Works

  1. Include math.h. That declares exp.
  2. exp(0) is 1. Any nonzero base to the power 0 is 1.
  3. exp(1) is e. This is how you get Euler’s number in code.
  4. exp(2) is e². Growth compounds as the exponent rises.

Example 2 — Negative Exponent (Decay)

Negative exponents give values between 0 and 1—useful for decay and damping models.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double y = exp(-1.0);

    printf("exp(-1) = %.6f\n", y);
    printf("1/e     = %.6f\n", 1.0 / exp(1.0));

    return 0;
}

How It Works

  1. Negative power. exp(-1) means 1/e.
  2. Cross-check. Dividing 1 by exp(1) matches.
  3. Always positive. For finite real x, exp(x) stays > 0.
  4. Decay pattern. As x goes more negative, the result approaches 0.

Example 3 — Inverse With log()

Natural log undoes exp (within floating-point error).

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double x = 2.5;
    double y = exp(x);
    double back = log(y);

    printf("x          = %.6f\n", x);
    printf("exp(x)     = %.6f\n", y);
    printf("log(exp(x))= %.6f\n", back);

    return 0;
}

How It Works

  1. Raise e. exp(2.5) grows to about 12.18.
  2. Take ln. log(y) is the natural logarithm.
  3. Recover x. log(exp(x)) returns to 2.5.
  4. Require y > 0. log is only defined for positive arguments.

Frequently Asked Questions

exp() returns e raised to the power x. exp(0) is 1, and exp(1) is about 2.718.
x is required. It is the exponent.
A positive double. exp(0) is 1.
Include <math.h>. On GCC, link with -lm.
A large positive x overflows to infinity. A large negative x underflows toward 0.

Next: exp2()

Get the absolute value of a floating-point number.

exp2() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful