C++20 sections · 1024 units
Open in Course

Quiz: Pointer Traversal

Avoiding errors

Check Your Understanding

What's wrong with this array sum code? int sum = 0; for(int i = 0; i <= size; i++) { sum += *ptr; ptr++; }

  1. A.Should use i < size, not i <= size
  2. B.Nothing, it's correct
  3. C.Should use ptr[i] instead of *ptr
  4. D.Should check if ptr is nullptr
Start the roadmap to answer the quizzes and solve the challenges