Rajahuroman's version gives an error under -Wall because the return statement in x returns an int while x is, I think, declared to return a pointer to array of 5 ints. Here's one that compiles without warnings:
Code:
#include <stdio.h>
int foo[] = { 1, 2, 3, 4, 5 };
int (*x(int))[5];
int (*x(int a))[5]
{
return &foo;
}
int main()
{
int i;
int (*p)[5];
p = x(3);
for (i = 0; i < 5; ++i)
printf("%d\n", (*p)[i]);
return 0;
}
changing "return (*p)[5]" to "return p" seems to work remove the warning from Rajahuroman's.
In short, x() is declared to be a function which takes an integer argument and returns a pointer to int, with the information that there are 5 integers starting at the spot to which the pointer points. Because the compiler sees *p as an array and not just an integer, (*p) can be indexed with [].
At least, that's what I guess after playing with a debugger on it. it's definitely some obscure C.