对了 at the start of a sentence means 'by the way' or 'oh right' — used to introduce a new topic or something you just remembered. At the end of a response it means 'that's correct'.
grammar
As an interjection, 对了 is always followed by a comma and a new clause. As 'correct', it stands alone or at the end of a sentence.