Corals are calcareous structures formed by animals, very small related to jellyfish, called coral polyps.
These, to protect themselves, secrete a limestone structure that appears like a rock.
Coral polyps live in symbiosis with microscopic algae called zooxanthellae.
They help each other: the algae do photosynthesis and produce sugars and other substances that are used by the coral polyps to feed themselves; in return, they get protection because of the calcareous structure.