Reputation: 6039
If I call a function in C and pass in a struct (not by pointers nor references for those c++ readers), it copies the object. If I pass in a struct with an array in it, it copies the array (as stated by professor in class). But what happens if I pass in a struct that contains a circular reference back to the object. How does it copy the whole struct?
Upvotes: 2
Views: 53
Reputation: 212574
It copies the struct, and the pointer inside the copied struct contains the address of the original object.
Upvotes: 4
Reputation: 726987
The only way to have a reference back to the same struct
is by adding a pointer to the struct
that points back. This pointer is copied in the same way as the rest of the struct
.
Upvotes: 2