1

Let's be clear:

I know the difference between the . and the -> operators

When working with a structure, the . operator is a simple offset added to the address of the structure. When working with a pointer to a structure, the -> operator first dereferences the pointer and then adds the offset.

My question is: Why were two operators introduced in the first place?

The compiler obviously knows whether I'm working with a structure or with a pointer to a structure, so it shouldn't require me to use the proper operator. With the single . operator, it could dereference the pointer by itself first if working with a pointer to a structure.

I ask myself this question every single time I use the improper operator, and I couldn't find the answer.

François
  • 171
  • 2
  • 10

0 Answers0