A. Generally when your neck hurts after sitting for a long time it's due to poor posture. Your head starts to lean forward and the muscles in the back of your neck have to work a lot harder to hold your head up. Imagine that you are holding a bowling ball (which is about the same weight as your head) close to your body. It isn't hard to hold it there for a long time without getting tired. Now imagine holding that ball out in front of you at arms length. It gets pretty hard to do pretty quickly. The same principle applies to your head and neck. The closer your head is to your center of gravity, the less work your muscles have to do to hold it in place.
There's a bunch of names for this such as forward head posture, anterior head position, reverse cervical curve, etc. They all lead to the same outcome however which is a condition called upper cross syndrome. Certain muscles become weak, while others become very tight (not to be confused with strong). The weak muscles are the ones between your shoulder blades, and the neck muscles that bring your chin to your chest, while the tight ones are your chest and upper shoulder muscles. The picture in teh upper left is a good illustration.
So the trick is to strengthen the weak muscles and stretch the tight ones. A great exercise to strengthen the neck is called a chin tuck. Imagine you have a string that pulls your head up and back essentially “tucking” your chin. Hold that position for a few seconds and then release. Do this 20 times or so and you will have begun to strengthen those neck muscles. This is a great exercise to do in the car or after a long time at the computer. A great stretch for the chest is to put your arms up on the door frame of an open door and lean forward. You should feel your chest open up and get a really nice stretch.
Of course the whole key to this is to be mindful of your posture. If you let your head go right back to slumping forward after doing these stretches, it's not going to make much of a difference. A good benchmark is to try to keep your ears over your shoulders. There are many more stretches and exercises that I don't have room to go into in this article, but if you are interested in changing your posture and reducing your neck pain and headaches, I would recommend you call your chiropractor.