Examinations are a form of evaluation, and the primary purpose of evaluation in education is to assess learning outcomes.
Before teaching a unit, a teacher has specific learning objectives—what students should know or be able to do by the end of the unit.
The prime objective of an examination is to measure the extent to which these teaching and learning objectives have been achieved.
The results provide feedback to the student about their progress and to the teacher about the effectiveness of their instruction.
While examinations may have secondary effects like promoting discipline or study habits, their main educational purpose is assessment of objectives.