When a company goes public it lists its shares on a certified stock exchange and offer shares through Initial Public Offering (IPO).
An initial public offering is offering of shares by a company at a price range which can be bought in lots. Buying an IPO doesn’t guarantee your allotment of shares.
If shares are not allotted in IPO than the amount is returned to the person who have appliedd for the IPO.
Then at some fixed date these shares will be listed on stock exchange.
After listing shares can be bought by a person.