Your brain has the ability to remember pitches. Obviously, some people can do this better than others. If you desire to recognize, or memorize pitches, then playing, or listening to music that is out of tune is counterproductive. If you are young, and serious about music, I would strongly discourage listening to, or playing music that is out of tune.
If you are interested in memorizing pitches, there is way to do this. Pick a note like C, or A. Learn what this note sounds like in all of the different keys, major and minor. Carry a tuning fork with you when you are away from your instrument and every time you think of it, see if you remember what the note sounds like. Use the tuning fork to check your memory against the tuning fork (or maybe a recording on your iPod).
When you hear music, on the radio, musak, whatever, car horns, 60 cycle hum (60 cycle hum is a Bb) learn how to identify that key or pitch relative to the pitch of your tuning fork. Make up little melodies that help you to relate the pitch on your tuning fork to all of the different major and minor keys. Learn how to sing these melodies using 'fixed do' solfeggi.'Fixed do' means concert pitch i.e. every solfeggi syllable corresponds to its proper pitch. 'Moveable do' uses the syllable 'do' to represent the tonic of any different key. Listen to your tuning fork while listening to music and listen to how the pitch of your tuning fork harmonizes with the music you are listening to i.e. how your tuning fork harmonizes against the various different keys, chords pitches and modes. As you feel confident, pick a different note and work on it using the same method. I bought a set of tuning forks, 13 forks. C,C#,D......up to C an octave above. I use only twelve syllables for solfeggi. I use the white key syllables; do(dough)re(ray)mi(me) fa(fah)so(so)la(law)ti(tee) do, and black key flat syllables; ra(rah)me(may)se(say)le(lay)te(tay). There are enharmonic sharp syllables as well. I find that using them creates confusion. It is better to always use the same syllable for the same pitch. In my opinion.
Some people think that you should work on a different pitch every week. I have been concentrating on a single pitch for maybe, a few months at a time. I have made definite progress. I can usually produce a C with my voice at any given time. Even if there is music in the background that is in a totally different key. With practice I tend to recognize different keys immediately.
If young children were encouraged to do this, they would develop absolute pitch.
There are articles about this if you are interested in learning more.
Be patient. You will make a lot of mistakes. But you can learn to do this. I got discouraged once and gave up. I was rummaging around in my bedroom and came across my C tuning fork. I immediately heard its pitch in my mind. It was like being slapped in the face. I checked, and was quite surprised that my memory of the pitch was spot on. In perfect tune.
Some people will say that this skill is not terribly valuable. It helped me to play in improvisational settings with other musicians. I can usually identify a key without having to play a note on my instrument. This a baby step toward developing what is commonly called 'perfect pitch', 'absolute pitch' or 'pitch memory'.
Sometimes I forget what a C sounds like. Just as sometimes I forget lots of things, like a person's name for example. That doesn't mean that I don't know the person's name, I have simply forgotten it momentarily.
I have noticed that when I play my guitar, I very often know what I am going to play, a D chord, for example, will sound like before I play it. In the past, my ear was not able to do as well as it can now that I have been paying attention to, and trying to remember what pitches sound like.
The conventional wisdom used to be that there are some people that have 'perfect pitch', but most people don't. This is not really true. 'Perfect pitch' is a function of memory. The human brain can learn to remember pitches. This is not an all or nothing issue. If you could not remember a pitch, you could not sing a song. The question is, "how long can you remember a pitch?" And can you remember it tomorrow? After I started trying, I noticed that most of time, I could sing a C perfectly in tune, first thing in the morning when I woke up.