It's partly dependent on the environment that the animal or the human is in, and the synapses that are being used are strengthened, and synapses that aren't being used in that particular environment are pruned away.