why $f$ and $g$ need to be bounded 
Let $f,g$ be bounded measurable functions on a set $E$ of finite measure.
  Show that:
If $f \displaystyle \overset{a.e.}= g $ then $\displaystyle\int_E f= \int_E g$ 
I have this proof from Cupta book, but I'm confused about why $f$ and $g$ need to be bounded and where we benefit from this information in this proof? 
What if $f, g$ are nonnegative, and unbounded? What will be exchange? 

$\quad$ (c) It is sufficient to show that
$$\int_E (f-g)=0.$$
Since $f-g=0$ a.e., it follows that if $\psi\geq f-g$, then $\psi\geq 0$ a.e. Therefore, in view of Theorem 2.2 (b), we have 
$$\int_E \psi\geq 0$$
Thus
$$\int_E (f-g)\geq 0.$$
Similarly, one can prove that
$$\int_E (f-g)\leq 0.$$
This proves the result.
 A: In many standard textbooks like Real Analysis by Royden and apparently this one, the Lebesgue integral is first defined for bounded measurable functions on a set of finite measure. With these restrictions the function is integrable when upper and lower Lebesgue integrals are equal and the integral is
$$\int_E f = \sup \left\{\int_E \phi \, \, | \, \,\phi \text{ simple },\,\, \phi \leqslant f \right\} =  \inf \left\{\int_E \psi \, \,| \, \,\psi \text{ simple },\,\, \psi \geqslant f \right\}$$
The basic properties of the integral like linearity, monotonicity and $f \overset{a.e.}= g \implies \int_E f = \int_E g$ are proved often by exploiting the assumptions such as boundedness.
Later the integral is defined more generally by building on this foundation.  For example, for a nonnegative function $f$ that may be unbounded on a set $E$ that may have infinite measure, the integral is defined as
$$\int_E f  = \sup \left\{\int_E h \, \, | \, \,h \text{ bounded, measurable, of finite support   },\,\, 0 \leqslant h \leqslant f \right\}$$
This definition relies on the earlier development of the integral for the bounded function $h$. The basic properties are then shown to extend.
The proof you included is clearly introduced at a point where the focus is on the Lebesgue integral for bounded, measurable functions defined on a set of finite measure. It uses two results that exploit boundedness.  
(1) Since $f-g$ is bounded and $E$ has finite measure , there exists a simple function $\psi$ such that $\psi \geqslant f-g$ on $E$. This is clear since boundedness implies there exists a number $M$ such that $f - g \leqslant M$ on $E$ and $\psi = M \chi_E$ is a simple function.
(2) For any simple function $\psi \geqslant 0$ a.e., we have $\int_E \psi \geqslant 0$. This follows almost directly from the definition of the Lebesgue integral of a simple function.
What if f,g are nonnegative and unbounded?
The theorem carries through and follows from: 

Let $f$ be a nonnegative, measureable function on a measureable set
  $E$. Then $f = 0$ a.e. if and only if $\displaystyle \int_E f = 0$.

The only if part is easily shown by taking $E_0 = \{x \in E \,\, | \,\, f(x) = 0\}$. We then have
$$\int_E f = \int_{E_0} f + \int_{E \setminus E_0} f$$
The first integral on the RHS is $0$ since the only bounded, measurable function $h$ of finite support on $E_0$ with $0 \leqslant h \leqslant f$ has  $h(x) = 0$ for all $x \in E_0$ and $\sup_h \int_{E_0} h = 0$.  The second integral on the RHS is also $0$ by again applying the definitions and using the fact that the measure of $E\setminus E_0$ is $0$.
