What is special about structs?

前端 未结 4 425
走了就别回头了
走了就别回头了 2021-01-30 16:03

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

4条回答
  •  遥遥无期
    2021-01-30 16:07

    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 structs.

    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 ints, doubles, etc. This includes any arrays embedded in the struct, except for flexible array members, which are not copied.

提交回复
热议问题