since I am currently learning pointers in C++, I am wondering about the syntax. So when I want to use a pointer on an object, I do not have to dereference it, in order to access the class attributes. When I just want to use a pointer on a simple variable, I have to use * for changing its values.
So why do I not have to use the * for the object? Because so I thought I would just change the memory address.
Object:
int age = 20; User John(age); User *ptrUser = &John; ptrUser->printAge(); // 20 (why no *ptrUser->printAge() ??? ) cout << ptrUser // 0x123456... Variables:
int a = 10; int *ptrA = &a; *ptrA = 20; cout << a // 20 Thank you very much!
->mean?