Why is this valid in C
int * foo(int a,int b){
...
}
but this is invalid
int [] foo(int a,int b){
...
}
First, recall that arrays in C are really just syntactic sugar around pointers to blocks of memory. So C isn't restricting the functionality of the language by forcing the use of the former notation (See the example which follows).
Also, they may have made this choice to prevent early programmers from writing code like this:
char *itoa(int n){
char retbuf[25];
sprintf(retbuf, "%d", n);
return retbuf;
}
ref
Which looks simple enough, but what happens to the memory retbuf points to at the end of the function? Can the calling functions trust the data in the pointer it gets back?