Please consider the following code:
// Thing is a typedef struct
void f(Thing* things, int size) {
for (int i = 0; i < size; i++) {
Thing my_thing = things[i];
my_thing.a = 10;
}
}
The array pointed to by things
is allocated somewhere on the heap.
And yet - my_thing
is a "stack variable" - allocated on the stack.
So what is happening behind the scenes? Is things[i]
copied to the stack and stored in my_thing
? And what does my_thing.a = 10;
do - does it modify the original things[i]
or does it modify the "stack copy"?