This is going to long, so have patience!
Adding to the 3rd point that Nithin made...
When you buy a stock of a company through a stock exchange, you are actually buying the common stock of a company, which is the most riskiest offering of a company in terms of its Capital Structure. Let me attempt to explain..
Assume that company ABC is on the brink of a bankruptcy situation. The companies operations are no longer profitable for the management to run the show. So they decide to wind up. Before winding up they realize that the company has some amount of land, property, inventory and other asset which can be liquidated. Let us assume they liquidate all these assets and recover 10Crs. Now how does the company decide who gets how much of this 10Crs?.
The answer depends on the Capital Structure of the company.
They will start distributing the 10crs by first paying the those that are there at the the highest level of the capital structure. To help you understand, I've created an image of a typical capital structure of a company.
Notice that the "Senior Secured Debt" holder is at the highest level and hence will first get paid out of the 10crs, after they are paid, the next person to get paid is the Senior Debt holder...so and so forth.
If you see, the Common Equity holder is the last in the Capital Structure...hence he gets paid only after everyone else gets paid. If there is nothing left on the table, obviously he gets paid nothing! This should also explain why equity is considered most risky and debt the most safest!
Hence as Nithin said, if company declares bankruptcy and they have no money to distribute to shareholders, there is nothing much you can do!
Afterall, you are taking maximum amount of risk by subscribing to the companies shares. Hence when you invest, make sure you review the balance sheet first!