Accidentals last only until the end of the measure in which they appear. In the example below, note C sharp (in bar 1) is cancelled by the bar line. This means that note C in bar 2 (beat 1) is no longer affected by the sharp.
How long does an accidental affect a note?
Unlike the key signature, an accidental is placed within a measure, just before the altered note. Its effect stops at the end of the measure in which it is placed.
What is the rule for accidentals?
Accidentals apply to subsequent notes on the same staff position for the remainder of the measure where they occur, unless explicitly changed by another accidental. Once a barline is passed, the effect of the accidental ends, except when a note affected by an accidental is tied to the same note across a barline.