In the past, the stock market was the exchange building or location where buyers and sellers of stocks use to bid and quote under the open-cry system. Since the National Stock Exchange (NSE) came into being in 1994, the concept of the physical location of the stock market has ceased to exist. Demat account or dematerialized account is an account that allows you as an investor to hold shares, bonds, government securities and mutual funds in electronic form.

Today, any investor can trade over the phone, on the internet using the web trading facility or even on their smartphones or notepads. Thus the stock market today is just a meeting point of buyers and sellers. That is exactly the traditional definition of a market in economics which is defined as the getting together of buyers and sellers.

The stock market, as we know it today, is a platform for buyers and sellers of equities to trade equities on the basis of a predefined set of rules and protocols. The most important role that the stock market play is that it helps buyers and sellers find each other anonymously and also helps in price discovery.Coming to your second query over transfer in the stock market. 

You need a Demat account for holding of shares and buying and selling of shares through debits and credits through the demat account. When you buy or sell the shares they are automatically debited or credited to your demat account respectively. 
However, demat account is not a transaction account. thus you must have a trading account. You cannot directly sell from your demat account or buying into your demat account.

In the stock market, Applications Supported by Blocked Amount (ASBA) allows the investor's money to remain with the bank until the shares are allotted after the IPO. The funds are transferred after the allotment and to the extent of allotted shares.