This is probably simple, but im trying to try and understand pointers better.
Lets say I have a struct
struct Person{
char Name[20];
char ID[15];
char Address[50];
char Number[15];
};
and lets say I have a bunch of these stored in memory like one after the other.
so now i declare a new pointer to the struct.
struct Person *ptr;
Will this Pointer start at the FIRST entry? (aka the first “Name”) and when I iterate it (aka ptr++) will it go to the next STRUCT or the next “entry” aka like name–>ID—>Address
So lets say Im on the first entry for example and the data is:
Jason Adams
111222333
111 Fake Drive
55555551000
and the second entry is
Matt Johns
111555333
555 Derp lane
1000022434
now I iterate the ptr (ptr++) will the ptr point to second struct (the one with matt johns) or will it point to Jason Adams “ID”
I hope this makes sense?
It will point to the second struct. The pointer will be advanced by
sizeof(Person).