18. Object Pointer Access

We have already defined a class Sensor with:

  • A public variable int value
  • A public method void printValue() that prints:
    Sensor Value: <value>

Your task is to:

  1. Declare a pointer to a Sensor object in main().
  2. Use the pointer to set value = 88.
  3. Call printValue() using the pointer.

     

Example

Output:

Sensor Value: 88

Why this output?

Because the object pointer is used with the arrow operator (->) to access the variable and function.

 

Question Significance

Introduces object pointers, showing how to access class members with -> instead of ..

Loading...

Input

Expected Output

Sensor Value: 88