57. Register Callback Counter

In embedded and firmware systems, callbacks are commonly used to react to events such as timers, interrupts, or state changes.
This task focuses on using a C++ lambda as a callback that captures and modifies local state without explicitly specifying its type.

Your task is to create a callback that increments a counter each time it is invoked.

You must follow the given constraints exactly, as they are designed to reinforce modern Embedded C++ best practices.

Task:

  1. Read an integer n from input.
  2. Declare an integer variable count initialized to 0.
  3. Create a callback that captures count and increments it by 1 each time it is called.
  4. Store the callback in a variable without writing any explicit type.
  5. Call the stored callback exactly n times using the provided loop.
  6. Print the final value of count.

Input Specification:

  • A single integer n
  • n represents how many times the callback should be invoked

Output Specification:

  • Print a single integer: the final value of count after the callback has been called n times
  • Output must not include extra spaces or newlines

 

Example

Input:

3

Output:

3

 

Constraints:

  • 0 ≤ n ≤ 10^6
  • The callback must capture count
  • You must not use:
    • Function pointers
    • std::function
    • typename
    • Any explicitly written callback type
  • The for loop must not be modified
  • Only the callback creation and storage line may be edited
  • The solution must compile using a standard C++ compiler suitable for embedded systems

 

 

 

 

Loading...

Input

0

Expected Output

0