-
p is a pointer to a structure – this means that p ‘holds’ the starting address for a structure in memory —
Hence: p = d.elmts+i represents the starting address in memory, for the current structure (i represents the address offset).
In this example memory has been allocated for ‘dictSize’ structures (i.e. the number of structures).
Note that the memory for the structures is allocated contiguously (i.e.next to each other) and can therefore be easily accessed using the start address of the reserved memory (i.e. d.elemts) and some offset i.e. i -
If a pointer to a a structure is declared then the underlying structure members can only can be accessed by the pointer when the arrow notation is used.
If a structure is declared (not a pointer to a structure) then the underlying structure members can be accessed using the dot notation. -
using the ‘[]’ notation in C – may be interpreted as trying to assigning an actual value (to memory that has been allocated) – whereas the pointer notation used in lines 50 and 51 is just enabling the allocating memory i.e. points to the start address of the memory being allocated – to hold possible values that each of the members may assume i.e. have not put values in this memory just yet – have to create/allocate memory first.
solved I need help trying to understand this piece of code about structures and pointers [closed]