David W. answered 03/19/19
Music Theory Professor and Composer with 5+ Years Teaching Experience
If you're looking at a bunch of consecutive notes, you're probably looking at a melody. If you're looking at a melody, it probably ends (and more than likely begins) with the tonic note of the scale—C, in the case of C major, or A, in the case of A minor.
There are other defining features of a given key—the 5th note of a scale is usually very important, for instance. So if G is the highest note in the melody, or repeated a lot, it's much more likely C major than A minor.
Also, minor keys usually have their 7th scale degree raised by half a step—you'll very often see G-sharp in A minor, whereas you'll much more rarely see it in C major.
Once you start looking at chords rather than just individual notes, there are more ways to tell. But this is a start.