Constant Member Functions (const at the end)

Easy Static Members & Friend Functions
Solve in Playground →

Problem Statement

Create an `Item` class with a private integer `price`. Provide a constructor to set it. Create a getter method `int getPrice() const` that strictly promises not to modify object state. Read an integer, instantiate the object, and print ‘Price: [val]’.

Input Format

A single integer.

Output Format

Print the formatted price.

Constraints

None

Sample Input

250

Sample Output

Price: 250

Explanation

Appending `const` to the end of a member function declaration guarantees that the function will not modify any member variables of the calling object.

Starter Code

#include <iostream>

class Item {
    // Define private state, constructor, and const getter
};

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