If you exercise a call, you must also pay the strike price of the call and likely another commission so your cost of exercising is the initial cost you paid for the option, the commission on the initial purchase, the cost of purchasing the stocks at the strike when exercising and potentially another commission fee for your broker. This catches some people who wait too long and find they can no longer sell the call option that close to expiration hence they must exercise it and sell the stock purchased at the strike in order to profit leaving them in a situation that although they made money on the option, they find they need a substantial amount more to realize that profit thereby winding up letting the option expire worthless.
If you exercise a put option, you must have the shares to sell at the put option's strike price. If you do not, then you must purchase shares on the open market, wait for the trade to settle (about 3 to 4 days) and sell the shares at the put strike. Some people wait too long and find they do not have enough time to purchase the stocks at market to sell at the put strike and must let the put expire worthless. This is also why the liquidity in the options market dries up well before the expiration of the options.
Writing an option is selling an option that you don't have hence you've created an option. If whomever holds the option decides to exercise it you must either sell them stock at the option's strike if it's a call option or buy stock at the strike if it's a put option. Alternatively you can purchase equivalent options to cover or similar options to mitigate your obligations. You may have to purchase shares on the open market to fulfill a call option that you wrote. As you need a margin account to write short any security, you'll find that although you sold the options and received funds for doing so, those funds are not available to you because of the obligations that you have which are marked to value on a daily basis. When you're exposure exceeds your funds and assets in the margin account, you will receive a margin call and must put more funds or assets into the margin or liquidate some assets. Note the margin call will probably come as you approach exceeding your funds so that liquidation of your assets would still cover your obligations, exactly when that call will come depends on your broker's policies. Unless you purchase an equivalent option to meet your obligations then the purchaser of a call option is purchasing the right to purchase the stock from you, if you cover with another option then that becomes a right to purchase from the issuer of the option that you bought to cover. Of course if you could only get a similar option, you may still be involved for the difference. If you bought an option and then sold it then you're out of the picture entirely
Writing a call option presents unlimited risk as the price of the underlying stock could go to infinity. Writing a put option does not have unlimited risk because the lowest the stock could drop to is to zero. Purchasing options limits your risks to what you paid plus commission for the options but for a call option the gain could potentially be unlimited if the stock goes to infinity where as a put option still has a limit on the potential gain as the stock price can not fall below zero.
Note that you can hedge writing a call option by purchasing a less expensive out of the money option thereby limiting your risk, by holding stock thereby trading any potential gains from your stock to cancel out the liability from writing the call or a combination of the two. Similarly, you can cancel out the risk of writing a put option by shorting the stock but this incurs unlimited risk with the short position on the stock which of course can be addressed with an out of the money call option.