This article has been amended since it was first published.

The giraffe is the tallest land mammal alive, its long legs and neck contributing to its impressive stature. Males can be up to 18ft (5.5m tall), females a little less.

In the wild, these beautiful creatures stretch their necks beyond those of antelope, kudu and even elephants to strip leaves from the untouched upper reaches of trees.

The French zoologist Jean-Baptiste Lamarck is usually credited as the first person to suggest that long necks have evolved in giraffes because they allow them to get to the parts other herbivores cannot reach.

As the giraffe lives "in places where the soil is nearly always arid and barren, it is obliged to browse on the leaves of trees and to make constant efforts to reach them," he wrote in his 1809 book Philosophie Zoologique. "From this habit long maintained in all its race, it has resulted that the animal's fore-legs have become longer than its hind legs, and that its neck is lengthened."

Long-necked giraffes were more likely to survive hard times than their short-necked rivals

In short, giraffes' long necks are the result of generation upon generation of repeated stretching and inheritance.

The English naturalist Charles Darwin also thought the giraffe's extraordinary legs and neck must have something to do with foraging. "The giraffe, by its lofty stature, much elongated neck, fore-legs, head and tongue, has its whole frame beautifully adapted for browsing on the higher branches of trees," he wrote in On the Origin of Species in 1859.

But Darwin did not buy Lamarck's ideas on how evolutionary change came about. Instead he argued that the giraffe's neck results from repeated "natural selection". Long-necked giraffes were more likely to survive hard times than their short-necked rivals.

It has since become clear that Darwin was largely correct about how evolution works, and that Lamarck got it wrong. So it is important to understand the difference between Lamarckian and Darwinian mechanisms of evolution.

Giraffes feed most often and faster with their necks bent

However, it is a bit of a shame that the giraffe is used to illustrate the point.

For a start, Lamarck made only a single, passing mention of giraffes in all his many writings. Yet it is this we remember him for – rather than the prescience of his ideas on evolution, which hugely influenced Darwin, or the many other contributions he made.

In addition, the idea pushed by both Lamarck and Darwin – that giraffes' long necks evolved to help them feed – may not be the whole story.

In 1996, zoologists Robert Simmons and Lue Scheepers set out several challenges to what has become known as the "competing browsers" hypothesis.

Male giraffes often fight for access to females, a ritual referred to as "necking"

"During the dry season (when feeding competition should be most intense) giraffe generally feed from low shrubs, not tall trees," they wrote in The American Naturalist. What's more, giraffes feed most often and faster with their necks bent.

There is also the question of why giraffes have been around 2m taller than any of their competition for over 1 million years. Surely, that is overkill.

The alternative, suggested Simmons and Scheepers, is that long necks have been sexually selected. This idea has become known as the "necks-for-sex" hypothesis.

Male giraffes often fight for access to females, a ritual referred to as "necking". The rivals stand flank to flank, then start to whack each other with their heads.

"The top or back of the well-armored skull is used as a club to strike the neck, chest, ribs, or legs of the opponent with a force capable of knocking a competitor off balance or unconscious," wrote Simmons and Scheepers.

The largest males usually win these battles and do most of the breeding

"The skull of the male giraffe appears to be highly specialised for its peculiar mode of intra-specific fighting," researchers noted in a study published in 1968.

In an extreme case, reported in the 1960s, one male punctured his opponent's neck just below the ear. The impact splintered a vertebra and a shard of bone entered the luckless giraffe's spinal column, killing him.

The largest males usually win these battles and do most of the breeding, says zoologist Anne Innis Dagg of the University of Waterloo in Ontario, Canada, who has been studying giraffes since the 1950s. "The other giraffes don't get much breeding opportunity."

There is also evidence that females are more receptive to advances from larger males.

However, in the last 10 years evidence has emerged that weakens the necks-for-sex hypothesis.

In particular, a 2013 investigation found no evidence that males have longer necks for their body mass than do females.

In other words, there is no obvious sexual dimorphism in neck length. As a result, the authors concluded that the "competing browsers" hypothesis "is the more likely explanation for tallness in giraffes".

In the last 10 years evidence has emerged that weakens the necks-for-sex hypothesis

Meanwhile, other researchers have found direct evidence for the competing browsers hypothesis. By erecting fences around Acacia trees in South Africa, Elissa Cameron and Johan du Toit were able to reveal the impact that smaller competitors like steenbok, impala and kudu have on food availability.

"Giraffes gain a foraging advantage by browsing above the reach of smaller browsers," they wrote in The American Naturalist in 2007. This was "the first experimental evidence that the giraffe's extremely elongated body form is naturally selected in response to competition from smaller browsing species."

These studies suggest that Darwin was right all along. But the necks-for-sex supporters have not given up, and it may turn out that there is some merit in both explanations. Either way, there could well be further twists to this story.

Update 1 July 2016: This article has been amended to clarify both that the necks-for-sex hypothesis remains highly contentious and that there is published evidence for the competing-browsers hypothesis

Join over five million BBC Earth fans by liking us on Facebook, or follow us on Twitter and Instagram.

If you liked this story, sign up for the weekly bbc.com features newsletter called "If You Only Read 6 Things This Week". A handpicked selection of stories from BBC Future, Earth, Culture, Capital, Travel and Autos, delivered to your inbox every Friday.