Let's say I spent 10k and bought some shares of stock A, where does the cash 10k go? Does it go to the stock broker and then the stock broker gives the money to the company of the stock A?
When you buy a share of stock, you are almost always buying from someone who previously purchased that share and now wants to sell it. The money -- minus broker's fee -- goes to that other investor, which may be a person, a company (rarely the company that issued the stock, but that will occasionally be the case), an investment fund, the "market maker" for that stock (websearch for definition of that term), or anyone else. They owned a small percentage of the company; you bought it from them and gave them the money for it, just as you would buy anything else. You don't know or care who you bought from; they don't know or care who they sold to; the market just found a buyer and seller who could agree on the price.
There are a very few exceptions to that. The company may repurchase some of its own shares and/or sell them again, depending on its own financial needs and obligations. For example, my own employer has to purchase its own shares periodically so it has enough on hand to sell to employees at a slight discount through the Employee Stock Ownership Program. But you generally don't know that's who you're selling to; it happens like any other transaction.
And during the Initial Public Offering, if you're lucky/privileged enough to get in on the first wave of purchases, you're buying from the investment bank that's managing this process ... though that's an almost vanishingly rare case for "retail" investors like us; we're more likely to get the shares after someone has already pushed the price up a bit.
But really, when you buy a share the money goes to whoever you bought it from, and that's all you can know or need to know.
2In brief: yes. The broker has direct access to the stock market. You can't afford that, so you go through them and pay them for the service. There are other Questions and Answers here which describe the process of matching up buyers and sellers in some detail; you may want to review those. You can sell/buy/give shares with a specific individual, but that is extremely rare unless you are doing something like making a charitable gift of appreciated stock -- which has also previously been discussed.– keshlamJul 17, 2016 at 5:10
2Even in the IPO the stock isn't sold to you by the company........ An investment bank (the underwriter) bought the shares and is reselling them....... Extra ellipses added to express my discomfort with consensus on this site– CQMJul 17, 2016 at 5:17
1@CQM: Granted, I oversimplified. Re consensus: corrections are part of the process, as are counter-answers if you disagree more generally. It's imperfect, but it's designed to be incremental.– keshlamJul 17, 2016 at 7:06
2@s-hunter The key word you are looking for is an exchange. The New York Stock Exchange is just one (very famous) example of an exchange - in this case focused on stocks. There are other stock exchanges and there are other types of exchanges. Aside from elsewhere on this Stack, you can find more information about exchanges with web and wikipedia searches. If somehow you still don't understand exchanges, you can always write a new question. Jul 17, 2016 at 8:55
2In rudimentary form, that is to say at some point in the past, a stock exchange is just a group of brokers sitting a room together, hollering at each other and/or waving signs to advertise prices that their clients would like to buy or sell at, in the hopes of finding a matching seller/buyer to make a deal. NYSE, as well as being a building, is a service currently owned and operated by a company called Intercontinental Exchange and uses computers to help actually make deals, but it's the same principle. NYSE and the Chicago Merc still support deals the old-fashioned way, by "open outcry". Jul 17, 2016 at 16:23
The money goes to the seller. There are a lot of behind the scenes things that happen, and some transactions are very complicated with many parties involved (evidenced by all the comments on @keshlam's perfectly reasonable high-level answer), but ultimately the money goes to the seller. Sometimes the seller is the company. The billions of shares that change hands each day are moving between other individuals like you and investment funds; these transactions have no direct impact on the company's financials, in general.