They are usually able to smell the blood of other animals who have gone before them. The slaughter itself is not painful. The cows are given a drug to put them in shock during the process, and then the blood is drained from their bodies until they are dead. It is required in most places that the cows be put in shock before this happens. It used to be that in some places the cows were drained while fully concious, but this rarely happens anymore.
Most people think that dairy cows have much better lives.
The truth is, their lives are not much better, maybe worse. The cows live in small spaces, with not even enough room to move around. Basically all they are are milk-producing machines. If they give birth to a male calf, it is quickly sent away to become veal. And once the cows are too old to produce milk anymore, they are just as likely to end up as hamburger as a beef cow.