Constant Objects and their Limitations

Medium Static Members & Friend Functions
Solve in Playground →

Problem Statement

Define a `Data` class with a private integer `value` and a `const` getter `int getValue() const`. In `main()`, instantiate the class as a constant object: `const Data d(val);`. Prove the object works by calling `d.getValue()` and printing ‘Const Value: [val]’.

Input Format

A single integer.

Output Format

Print the retrieved constant value.

Constraints

None

Sample Input

99

Sample Output

Const Value: 99

Explanation

If an object is declared as `const`, it can ONLY invoke member functions that are also marked as `const`. Attempting to call non-const methods would cause a compiler error.

Starter Code

#include <iostream>

class Data {
    // Define members and const getter
};

int main() {
    // Read input, instantiate const Data, 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