Originally Posted by
min2max
Yes this helped ! Thanks. When I said I was new to programming I meant I haven't done it in awhile so I needed to refresh on some things lol sorry if I didn't clarify that correctly.
So I guess I can just look at the char **array as a 2d array inside of the struct??
You need two mental models.
We can have
Code:
struct employee
{
char name[32];
int id;
float salary;
};
/or */
struct employee2
{
char *name;
int id;
float salary;
};
For a lot of purposes, the two methods are exactly the same. printf("%s %d %6.2f\n"employee.name, employee.id, employee.salary); will give you the same result.
But the way the data is stored in memory is different. In the first case we have a fixed field
32 bytes [name]
4 bytes [id]
4 bytes [salary]
in the second case we have a pointer field
4 or 8 bytes [name pointer]
4 bytes [id]
4 bytes [salary]
pointers will be 4 bytes on a 32 bit system, 8 bytes if we have 64 bits.
The pointer will point to memory somewhere else in the computer. Typically this will be allocated with malloc() so the structure will "own" the memory. But it could be a big list of names somewhere.
You've got to toggle between thinking of name as a field containing the employee's name, and a pointer to some memory somewhere, depending on what you are doing.