A short time later the husband comes back with 6 cartons of milk.
The wife asks him, "Why did you buy 6 cartons of milk?"
He replies, "They had avocados."
What makes the above joke humorous is actually called zero anaphora or gapping.
The Summer Institute of Linguistics defines anaphora as the "coreference of one expression with its antecedent. The antecedent provides the information necessary for the expression’s interpretation. This is often understood as an expression 'referring' back to the antecedent."
For example, in the sentence, "John rode his bike to town so he wouldn't have to worry about finding a parking spot", "he" is an anaphoric expression that refers back to the subject "John".
Zero anaphora is defined by SIL as "the use of a gap, in a phrase or clause, that has an anaphoric function similar to a pro-form*. It is often described as “referring back” to an expression that supplies the information necessary for interpreting the gap."
*A pro-form is a word, substituting for other words, phrases, clauses, or sentences, whose meaning is recoverable from the linguistic or extralinguistic context.
Now, look at the first line of the joke again:
A wife asks her husband, "Could you please go shopping for me and buy one carton of milk, and if they have avocados, get 6 [gap]."
The gap leaves open the possibility of referring back to either noun phrase, "avocados" or "one carton of milk". However, it makes more sense to start the anaphora resolution process by looking at the nearest antecedent first.
Now go return those five cartons of milk and bring me my six avocados, silly man.
Avocado image via.