El bolígrafo es de mi amigo (the pen belongs to my friend)
Necesito un bolígrafo (I need a pen)
Why is el used in the first sentence and un in the second? How would the meaning change if the second sentence used el instead of un?
Answer 1: The use of the definite article "el", in the first sentence means that the object that accompanies it and with which it must agree on gender and number (masculine and singular) is already known by the speaker or the speaker believes that the listener knows what he is referring to, however using the indefinite article "un" in the second sentence, means that the object that accompanies it and that also must agree on gender and number (masculine and singular) is generic and not yet known by the speaker or the listener.
Answer 2 : If in the second sentence the definite article "el" were used it would mean that it does not need any pen as now indicated by the indefinite article "un" but "el" specific pen already known by the speaker or the speaker believes that the listener knows what he is referring to.