StudyGraph
Procedural Programming with C++ Don't do this

3 expression mistakes that cost C++ marks

3 mistakes that cost marks in C++ expressions. Say the fix first.

Lesson notes

Evaluate expressions using precedence, integer division, modulus and implicit/explicit casts

Key points

Takeaway: Cast an operand to double before dividing, not the result.

Quick check: With int sum = 15 and int count = 4, what does sum/count evaluate to?
  1. 3.75
  2. 3
  3. 4

Both operands are int, so integer division drops the fraction, giving 3.

operator precedenceinteger divisionstatic_cast

Lessons like this, for your syllabus.

Short narrated study videos written for your course, level and exam. Free to start.

Get lessons for your own syllabus