Counting Active Instances of a Class

Medium Static Members & Friend Functions
Solve in Playground →

Problem Statement

Create a `User` class with a public static integer `active_users` initialized to 0. Inside the `User` constructor, increment `active_users` by 1. In `main()`, read an integer N, dynamically create an array of N `User` objects, and print ‘Active Users: [count]’.

Input Format

A single integer N.

Output Format

Print the total number of active users.

Constraints

0 <= N <= 100

Sample Input

5

Sample Output

Active Users: 5

Explanation

Because static variables are shared across all instances, they serve perfectly as global counters for object instantiations.

Starter Code

#include <iostream>

class User {
public:
    // Declare static counter and constructor
};

// Initialize static counter

int main() {
    // Read N, create an array of N Users, and print the counter
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used