Actually the sun is not yellow but white as seen from space. The reason why the sun normally appears to be yellow is because of its heat and energy and the place from where we view it from. Temperature on the sun's surface is approximately 5780 K, and is what that gives the sun its color, which originally is white.
Sunlight appears as yellow because of the temperature at which it is burning and the interference in the atmosphere that filters out other colours of light that it emits. As noted throughout the day, sunlight may actually appear to change from yellow to orange to red (and perhaps other colours) depending on the amount of interference in the atmosphere that refracts the light.
The sun appears yellow because white light that it emits scatters through the atmosphere. As the sun sets it appears more orange since it interacts with more atmospheric particles. Sometimes right before it sets for a few seconds it can even appear green.