Giraffe has long neck because:
Due to evolution and adaptation
According to Lamarck, evolution is a gradual process and it occurs by accumulation of changes over generations.
Giraffe had to feed on leaves that were the only food available by continuous stretching of neck and forelimbs.
This increase in neck length passed on to generations in which further elongation occurred due to similar efforts.