Option payoffs

On page 101 of the derivatives textbook, example 1F asks to determine the payoff for the following: The underlying stock is priced at $40. A call option with an exercise price of $40 is selling for $7. You buy the stock and sell the call. At expiration the stock price is 52. The textbook states that the payoff is 40 but I don’t understand this. Since you are selling the call and the stock price went up how could you have a positive payoff?? Any help on this would be much appreciated

by selling the call option , you are giving the buyer an option to buy the stock. now, since the option expires in -the- money, the buyer of the option would get $12 from you. Max{0,(52-40)}.It doesn’t involve actual delivery of the underlying. You now can sell the underlying for $52 in the market , your payoff would be 52-12=$40 This is what I understand.

don’t confuse payoff with profit. Two different things. At t=0, your net outlay is -$40 for the stock, +$7 for the option premium. Total outlay is -$33 At t=expiration, the option is worth -$12 to you, and your stock is worth +$52. Total payoff at expiration is $40. $40 + (-$33) = profit of $7

I was actually confusing profit with payoff. Thanks for the clarification guys