The other thing you have to worry about, depending on how deep you are when you run out of air, is the "bends."
The air we breathe is a mixture of mostly nitrogen (78 percent) and oxygen (21 percent). When you inhale air, your body consumes the oxygen, replaces some of it with carbon dioxide and does nothing with the nitrogen. At normal atmospheric pressure, some nitrogen and oxygen is dissolved in the fluid portions of your blood and tissues.
As you descend under the water, the pressure on your body increases, so more nitrogen and oxygen dissolve in your blood. Your tissues consume most of the oxygen, but the nitrogen remains dissolved. All this dissolved nitrogen is where the bends come from.
If you ascend rapidly, the nitrogen comes out of your blood quickly, forming bubbles. It's like opening a can of soda: You hear the hiss of the high-pressure gas and you see the bubbles caused by the gas rapidly coming out. This is what happens in your blood and tissues if you come up too fast. You get the bends (which is also called decompression sickness) when nitrogen bubbles form in your system and block tiny blood vessels. This can lead to heart attacks, strokes, ruptured blood vessels in the lungs and joint pain (one of the first symptoms of decompression sickness is a tingling sensation in your limbs).
The best way to avoid decompression sickness is to follow the no decompression depths and bottom times provided by dive tables. If you violate the no decompression limits, you have to stay underwater longer, for various times at pre-set depths (determined by dive tables), to allow the nitrogen to come out of your system slowly. This obviously presents problems because you're out of air. So what do you do? The only thing you may be able to do is come up, get another tank, and then immediately dive back down to a safe depth. But if you're near shore, you may be able to go to a decompression chamber instead, which is much safer.