Monolinguals often assume that this kind of switching happens because speakers are not competent in one of their languages - a sort of deficit hypothesis - or because a concept just can’t be expressed in one of the languages - a sort of lexical gap explanation. Analysis of recorded multilingual speech doesn’t support these ideas, however. Speakers who code-switch the most often are usually those who are the most fluent in both of their languages, and there are linguistic rules about where in a sentence a switch can happen.
Van Herk, What Is Sociolinguistics, chapter 11. (via transliterations)
The Wikipedia article on code-switching has a nice classification of the types and linguistic rules involved:
- Intersentential switching occurs outside the sentence or the clause level (i.e. at sentence or clause boundaries). It is sometimes called "extrasentential" switching. In Assyrian-English switching one could say, “Ani wideili. What happened?” (“Those, I did them. What happened?”)
- Intra-sentential switching occurs within a sentence or a clause. In Spanish-English switching one could say, “La onda is to fight y jambar." ("The in-thing is to fight and steal.”)
- Tag-switching is the switching of either a tag phrase or a word, or both, from one language to another, (common in intra-sentential switches). In Spanish-English switching one could say, “Él es de México y así los criaron a ellos, you know.” (“He’s from Mexico, and they raise them like that, you know.”)
- Intra-word switching occurs within a word itself, such as at a morpheme boundary. In Shona-English switching one could say, “But ma-day-s a-no a-ya ha-ndi-si ku-mu-on-a. (“But thesedays I don’t see him much.”) Here the English plural morpheme -s appears alongside the Shona prefix ma-, which also marks plurality.