Skip to content
Exercise · Variables and Types · lesson 10 of 10

Exercise: call counter

Write the function int next_id(): each call returns the next number in order, starting from 1.

  • first call next_id() → 1
  • second call next_id() → 2
  • third call next_id() → 3

Constraints: the checks call next_id() four times in a row, and the program makes no other calls.

next_id.cpp — cpp
cpp · 4 lines
Ctrl+Enter run · Esc leave editor