Search code examples
carraysreturnreturn-type

Why can't C functions return an array type?


I am new to C language and am wondering:

Why can't C functions return an array type?

I know that an array name is an address to the first value of the array, and arrays are second-class citizens in C.


Solution

  • You answered the question yourself already: arrays are second-class citizens.

    C returns by value. Arrays cannot be passed by value, therefore they cannot be returned.

    As to why arrays cannot be passed by value: this was a design decision made by K&R when they were first designing the language, and it's too late to change it now because all the existing C code would break.