I know that in C we cannot return an array from a function, but a pointer to an array. But I want to know what is the special thing about structs
that makes them re
A better way of asking the same question would be "what is special about arrays", for it is the arrays that have special handling attached to them, not struct
s.
The behavior of passing and returning arrays by pointer traces back to the original implementation of C. Arrays "decay" to pointers, causing a good deal of confusion, especially among people new to the language. Structs, on the other hand, behave just like built-in types, such as int
s, double
s, etc. This includes any arrays embedded in the struct
, except for flexible array members, which are not copied.