Answer :

First of all, the purpose of natural selection is to "weed out" the organisms in a species with imperfect qualities.  Basically, it's evolution's way of making the species that best it can be.

An anteater eats insects (namely, ants) by sticking its snout and tongue through anthills and the ground.  Obviously, the longer the snout of the anteater, the more possible bugs it can reach and, therefore, eat.  So, over millions of years, anteaters with shorter snouts were not able to reach enough bugs and ended up dying.  The anteaters with longer snouts had more food available because they could reach more bugs, so they were able to live long enough to reproduce and produce offspring with the preferred trait:  having a longer snout.