What happens to a stock when a company goes bankrupt depends on the bankruptcy case. There are 2 of them: Chapter 7 and Chapter 11. Chapter 7 is a total liquidation of business, when all assets are being sold and distributed in the following order:
1) Secured creditors
2) Unsecured creditors
3) Shareholders.
Usually, there is very little money left for shareholders and stocks become practically worthless.
If a company files for Chapter 11 bankruptcy, then it gives a chance to reorganize business. But while it happens, stocks will be delisted from major exchanges. You can keep them and hope for the company to gain glory again.