Misconception: With conditionals, students may try to compare the memory address of a function to a number, like x < foo, when they intended to compare x with the return value of foo.

  • Less than, less than or equal to, etc. are things introductory students understand in math but not in programming yet.
    • Not understanding these comparisons in a computer science context is at the root of this misconception.
  • This misconception happens when foo is function pointer, not the function.
    • In this scenario, it is very likely that x is is somewhere between 0 and the memory address containing foo, resulting in a true conditional statement.
      • This is not what they actually wanted to be comparing.
    • Getting students to understand that this isn’t a legal construct in a programming language is very important.
  • Extra information from CS Teaching Tips: For additional practice, have students check out CodingBat.

More about this tip

External Source

Interview with Walt Schilling