Search code examples
cfunctionsyntaxdynamic-memory-allocationreturn-type

Function return type syntax


In a function I am building a dynamically allocated 2D array. This array has a variable number of rows and a fixed number of columns (3). I would like to have this function return the array but I can't seem to get the operators precedence for the return type right.

The array has been defined as:

int (*refined_list)[3];

The attempts I have made up so far:

int (*)[3] funcName(int arg);
(int (*)[3]) funcName(int arg);
((int *)[3]) funcName(nt arg);
int ((*)[3]) funcName(int arg);

Solution

  • It's

    int (*funcName(int arg))[3];
    

    The "thing" you want to declare goes inside the (*).