Pointers to Class Members

Hard Encapsulation, Access Specifiers & The this Pointer PRO
🔒 Login to Unlock

Problem Statement

Create a `Data` class with a public integer `value`. In `main()`, declare a pointer to the class member `value` using the syntax `int Data::*ptr = &Data::value;`. Instantiate `Data`, read an integer, assign it to the object using `obj.*ptr = input;`, and print it using the same pointer.

Input Format

A single integer.

Output Format

Print 'Pointer Value: [val]'.

Constraints

None

Sample Input

42

Sample Output

Pointer Value: 42

Explanation

C++ allows declaring pointers that point to class attributes generally, and they must be evaluated against a specific instantiated object using `.*` or `->*`.

Starter Code

#include <iostream>

class Data {
public:
    int value;
};

int main() {
    // Create member pointer, instantiate, read input, assign, 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