During an ICO on Ethereum, participants send ether to a special smart contract, and, in return, receive tokens of equal value, depending on the price of the token set at the start of the sale.
In Ethereum, a token is just a balance – itself just a number – stored in a smart contract and associated with an owner's wallet address. A minimal implementation of a token would therefore only require a way to store how many tokens a given address owns. In Solidity, this can be achieved simply by using a mapping:
mapping (address => uint256) balances;
It's important to note that a token isn't something that resides in a user's wallet, nor is it something that can be moved around. When a user sees a token in their wallet, the wallet software is really making a call into the token contract and reading the balance associated with its address...