ProgrammingHard

A program reads a number n and then loops for (i = 0; i < n; i++) with n = 10^9 and a constant body. Roughly how long does it take in C for a simple body?

  1. A. Less than a millisecond
  2. B. About 10 minutes
  3. C. About one second or a little more, which is borderline for typical limits
  4. D. Unbounded, because the compiler cannot optimise loops

Correct answer: C. About one second or a little more, which is borderline for typical limits

A simple loop runs about 10^9 iterations per second on modern hardware, so the time is borderline. A closed-form answer avoids the loop.

More C Programming questions

Exams that ask this topic