Slices of the pdf
Consider an infinitesimally small interval of width \(\delta x\).
\[ P(x \lt X \lt x+\delta x) \;\approx\; f(x) \times \delta x\]If the range of possible x-values is split into many such slices, the definition of an expected value for a discrete random variables would give
\[ E[X] \;\approx\; \sum {x \times f(x) \; \delta x}\]where this summation is over all slices. In the limit, this summation becomes an integral, giving us the following definition.
Definition
The expected value of a continuous random variable with probability density function \(f(x)\) is
\[ E[X] \;=\; \int_{-\infty}^{\infty} {x \times f(x) \; d x}\]The concept is similar to that for a discrete random variable and can be generalised to define the expected value of an arbitrary function of \(X\), \(g(X)\).
Definition
If \(X\) is a continuous random variable with probability density function \(f(x)\), the expected value of \(g(X)\) is
\[ E\big[g(X)\big] \;=\; \int_{-\infty}^{\infty} {g(x) \times f(x) \; d x}\]