Actually, the cow eats grass and bacteria eat the grass and the cow gets nutrients from being able to breakdown the bacteria. A complex story but one that is based on a mutation - the replication of a gene. Keep in mind, mutations can be negative and most are. Mutations can also be neutral to natural selection. In that case, it may hang around and may or may not ever be useful.
Mutations can also be positive.
In this sense, they prove to be adaptive for some reason.