Register Callback Counter

#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    int count = 0;

    // Create a callback that captures count and increments it
    // Store it WITHOUT writing any explicit type
    // <write your code here>
    auto callback = [&count]() {
        count++;
    };

    for (int i = 0; i < n; i++) {
        callback();   // must increment count
    }

    cout << count;
    return 0;
}
Upvote
Downvote
Loading...

Input

0

Expected Output

0