-1

I have the following code:

class Person {
    public:
      int age;
      string name;
};

int main() {
  Person ben;
  ben.age = 30;
  ben.name = "Ben";
  Person * ptrBen = &ben;

return 0;
}

If i want to change the value stored in the age variable of the ben object to 35 for example, I can write in main():

ptrBen->age = 35;

Is there a difference between this and the following?:

(*ptrBen).age = 35;
Reno
  • 1,039
  • 3
  • 14
  • 22

2 Answers2

2

There is no difference whatsoever between ptrBen->age = 35; and (*ptrBen).age = 35; when ptrBen is a pointer. They do the exact same thing.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
1

No, there is no difference. ptrBen->age = 35; might be more readable though.

Galan Lucian
  • 103
  • 1
  • 2
  • 9