The female is generally larger than the male (left).
Abdominal segment A5 is dimorphic in melanogaster (right). The male's A5 segment is pigmented in the anterior half, and female's A5 is not (arrows). However, this can be difficult to discern in newly eclosed flies and/or yellow mutants. More reliable characters to score are shown below:
The male forelegs uniquely have a row of dark bristles known as the sex comb (left). They are visible in late-stage pupae as well.
The genitalia are the easiest and most reliable character to use in determining sex (right; ventral view, posterior is up). Note the circle of darkly pigmented parts in the male. In contrast, the tip of the female's abdomen is lightly colored and pointed.
Photos by Kevin Edwards