So I now understand that struct assignments is a combination of memcpy()(which apparently works as memory is allocated contiguously for structure variables) and some optimization stuff by the compiler.
But what happens if you use struct assignments when the structure definition contains a pointer?
struct S
{
char * p;
};
char array[]="hi";
struct S s1, s2;
s1.p = array;
s2 = s1;
Based on the above code: Since there is overlap to what &s1 and &s2 points to as s1.p==s2.p, shouldn't there some sort of Undefined Behaviour(UB) as the structure assignments employ memcpy() underneath the hood?
However, https://stackoverflow.com/a/2302357/10701114 (code example used in his answer slightly varies from mine) states:
Now the pointers of both structs point to the same block of memory - the compiler does not copy the pointed to data.
This is completely off from my assumptions: Not only does such a struct assignment work without invoking UB but memcpy() hidden with the struct assignment doesn't work as intended when the compiler doesn't copy the pointed to data but instead cause the pointers to point to the same memory as mentioned in quote.
To reiterate my question: what happens if you use struct assignments when the structure definition contains a pointer? Why am I wrong in my assumptions?