Register Callback Counter

#include <iostream>

int main() {
    int n;
        // Read input n
            if (!(std::cin >> n)) {
                    return 1; // Handle potential input error
                        }

                            int count = 0;

                                // Create the callback using auto
                                    auto increment_callback = [&count]() { count++; };

                                        // The provided loop to call the callback n times (must not be modified)
                                            for (int i = 0; i < n; ++i) {
                                                    increment_callback();
                                                        }

                                                            // Print the final value of count
                                                                std::cout << count << std::endl;

                                                                    return 0;
                                                                    }
                                                                    

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

0

Expected Output

0