All animals need various nutrients—things like amino acids and vitamins — to build and maintain their cells and to provide energy for bodily processes.
Carnivorous animals get many of these nutrients ready-made from the other animals they eat. Vegetarian animals get the nutrients not just by chemically changing plant material through enzymatic processes but also from the action of beneficial fermentation microbes in their guts and from the bodies of the microbes themselves.
Omnivorous animals, like humans and pigs, can obtain their nutrition from both animal and plant food, or from either one.
In the cow, for one vegetarian example, there is a multi-stomach system. In the large, multi-compartmental forestomach, microorganisms ferment plant cellulose and release volatile fatty acids; the acids come into contact with cells with a large surface area that absorb them to provide much of the energy supply.
Later on in the digestive process, chewed and rechewed food enters a true stomach and intestines, more like those of humans, where it is mixed with more digestive juices that change the chemistry of the food.
There, amino acids and other nutrients are absorbed and the bodies of the microorganisms from the fore-stomach are also digested.