If your long option expires even .01 in the money it will be automatically exercised, unless you file a contrary exercise notice. As others have said, your broker may liquidate your position if you don't have the capital to cover the exercise.
If you are short an option, it is a bit different. A short out of the money option may be assigned or an in the money one may not be. This is because the owner of the option has time after the close of the stock to decide whether or not to exercise it. Their decision will based on after market trading in the stock. For example say I am long the MSFT 135 puts. MSFT closes at 136, so normally I wouldn't want to exercise them, as they are out of the money. But, say just after the close some news comes out and MSFT falls to 131 in after market trading. Now it would be advantageous to exercise these puts.
If you are short an option, it is a bit different. A short out of the money option may be assigned or an in the money one may not be. This is because the owner of the option has time after the close of the stock to decide whether or not to exercise it. Their decision will based on after market trading in the stock. For example say I am long the MSFT 135 puts. MSFT closes at 136, so normally I wouldn't want to exercise them, as they are out of the money. But, say just after the close some news comes out and MSFT falls to 131 in after market trading. Now it would be advantageous to exercise these puts.