Why can C functions not return arrays?

前端 未结 4 1103
半阙折子戏
半阙折子戏 2021-01-21 09:41

In C, a struct (record data structure) can be the return type of a function, but an array cannot be. What design characteristics of the C Language cause arrays to b

4条回答
  •  梦毁少年i
    2021-01-21 09:59

    The characteristic is that in the small and speedy C language you don't want the equivalent of large memcpy operations when returning. If you badly need arrays returned, make them a member of a struct, and voila, array return in C. Sort of, starting with C89 :-)

    Or use a memcpy yourself when and where you need it.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题