Cadmium is a vibrant pigment used in paints (yellow, orange, and red). If you look at an artists selection of paints, they are actually labeled Cadmium Yellow, etc.
Lead is an additive to paint that helps it retain its depth of color for longer.
In the case of the cup, it is probably the decoration on the side that has these ingredients. Then the cup is dipped in a clear glaze (which may contain lead) and fired at high heat (which turns the cup from clay to ceramic and essentially bonds the cup, paint and glaze into a single piece (that is probably not a good technical statement, but try scraping the paint off any normal ceramic piece). Once fired, the lead and cadmium are locked into the structure of the cup.
Pottery is a different story as it is often not fired to such high temperatures resulting in lead a cadmium that is available to leach into food or drink.
I'm reaching here, but think it is fair to say you can tell the difference by the sound if you tap it. High temperature ceramics have a crystalline ring while low temp pottery has a dull thud. (of course both will have a dull thud if your hand is wrapped around them
).