Dear student,
Cactus prepare their food through the process of photosynthesis, like any other plant. Since, Cactus have their leaves reduced to spines, therefore photosynthesis takes place through the stem. The stems are green due to the presence of Chlorophyll to make food for the plant.
Regards.