For (symmetric) encryption you need a secret key for encryption and decryption.
Usually, the password you supply is used as the source of this key. For various security reasons, the password is not (and often cannot, due to requirements of the cipher used) directly used as the key. Instead, a key derivation function is used to generate the key from the password.
This is why passwords for encryption must be long and fairly random: Otherwise the resulting key will only come from a very small subset of possible keys, and these can then simply all be tried, thus brute-forcing the encryption.
As to code examples, there are several possibilities:
- look at the source code of a crypto library, such as OpenSSL
- look at the source code of a program that implements encryption, such as GnuPG
- google some sample source code for a simple encryption algorithm, or a key derivation function, and try to understand it
This depends on what you want to learn.