In the book "C Programming: A Modern Approach" the following quasi-code is supplied to the reader:
struct part {
int number;
char name[NAME_LEN+1];
int on_hand;
} part1;
void print_part (struct part p)
{
...
}
struct part inventory[100];
print_part(inventory[i]);
inventory[i].number=883;
inventory[i].name[0] = `\0`
So, in summary, the author creates a data type called struct part, creates a function called print_part that takes as its argument a variable p of data type struct part, creates an array called inventory that stores 100 different structures of type struct part, and then makes the following call to the aforementioned function: print_part(inventory[i]), where i could take on any arbitrary values between 0 and 99.
In the above function call, is inventory[i] functioning as a pointer? At first I thought certainly not (because print_part's prototype statement specifies that the function's parameter is a struct variable...not a pointer to struct).
However, the subsequent usage of inventory[i].number=883 and inventory[i].name[0]='\0' made me reconsider that, perhaps, it does function as a pointer.
In the case of inventory[i].name[0], it seems like inventory[i] is establishing a base address and from that base address, there is an offset to the 2nd field of the struct part data type, name. This strikes me as very "pointer-esque". Any clarification would be greatly appreciated!
print_partreceives a copy ofinventory[i]. There is no "functioning as a pointer" involved, and I don't see in the question anything that would suggest that, so I am not sure where the confusion lies that prompted the question..operator. So I guess the question was not necessarily specific to "arrays" per say...more so to struct variables.array[i]refers to thei'th element in anarray. There is really no difference whether the array isint[]orstruct part[]. And a function that takes a (non-array type) argument receives it by value, again no difference whether is a plainintor astruct part.