Pointers

12.4 - Pointer member access


The arrow operator -> can be used to access an object member through a pointer.

The effect is equivalent to using the dereference operator * the the dot operator . :

p->n
(*p).n // Same operation as the first one.

Task

  • Use the arrow operator -> to print out the x and y in a line each member of p:
    • p->x and p->y to access x and ymembers.
#include <iostream> struct Point { int x; int y; }; int main() { Point point{3, 4}; Point *p{&point}; // Print out x and y through p after this line: }