Passing Objects as Function Arguments

Medium Introduction to C++ Classes & Objects PRO
🔒 Login to Unlock

Problem Statement

Define a `Counter` class with a public integer `count`. Create a standalone function `void increment(Counter& c)` that accepts the object by reference and adds 1 to `count`. Read an integer to set the initial count, pass the object to `increment`, and print “Count: [count]”.

Input Format

A single integer.

Output Format

Print the incremented count.

Constraints

None

Sample Input

5

Sample Output

Count: 6

Explanation

Passing an object by reference (`&`) allows the function to modify the original object's data in memory rather than operating on a local copy.

Starter Code

#include <iostream>

class Counter {
public:
    // Define count here
};

// Define increment() here

int main() {
    // Instantiate, read input, call increment, and print
    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