Hello. Giraffes with longer necks survive compared to those with shorter necks because of natural selection. Over time, natural selection favors the traits that would make a species thrive better in the environment. Giraffes with short necks won't have access to that much food compared to those with long necks thus they eventually died out.
ANSWER: natural selection.