This paper considers the power allocation problem in device-to-device (D2D) communication underlaying a cellular network and investigates the impact of different transmitting and interference power constraints on the energy efficiency and spectral efficiency of the network. We formulate the power allocation problem in D2D communication as a nonlinear fractional programming problem with an objective to maximize the energy efficiency of a D2D communication link subject to four different combinations of transmitting and interference power constraints. To solve the original formulated nonlinear fractional programming problem, we first convert it into a dual nonlinear parametric programming problem, and then decouple the dual problem into several solvable concave problems. Further, a closed-form solution is derived to each dual problem and an efficient power allocation algorithm is proposed to find a numerical solution to the formulated problem. Simulation results show that the proposed power allocation algorithm outperforms an ergodic capacity maximization algorithm and a uniform power distribution algorithm in terms of the energy efficiency of a D2D link, and can efficiently improve the overall ergodic capacity of a cellular network.