var is array[10] of array[10] of pointer to pointer to function returning pointer to function returning pointer to pointer to array[] of pointer to array[] of pointer to int
how do you initialize that? it's quite wicked.
var is array[10] of array[10] of pointer to pointer to function returning pointer to function returning pointer to pointer to array[] of pointer to array[] of pointer to int
how do you initialize that? it's quite wicked.
Not possible. There is no way in C to declare a function that returns an array[] of anything.
I ment the afferwnt c code. I thing its something like var=*******array[10][10]; and it says that functiom returns pointer!!
It still won't work... the array would be destroyed as the function exits, leaving you with a pointer to nothing.
Can you explain me please what you ve had said.. I dont undwrstand.
Remember your moral teaching, and eschew this wickedness!it's quite wicked.
i've figured it out until about here: int*(*(**(*(**var[10][10] ...
With nullptr.
Array and function types will wrap around the variable they name.
An array of type T is defined as follows:
Usually, the parenthesis around the name are omitted, as they are not needed. However, they are needed when you make a pointer to the array. Putting the * in front of the '(', or without the '(' would make the contained type a pointer. Putting it after '(' will make an array pointer.Code:T (name)[X]
Functions are similarly defined:
Again, the first () are optional, except when defining a function pointer, and for exactly the same reason.Code:T (name)()
Arrays stack so that the outer type or the array is closer to the name:
This defines an array size X of array size Y of T. Again, both sets of parenthesis are optional when not further qualified.Code:T ((array)[X])[Y]
Functions work exactly the same way; a function returning a function pointer will have the inner parameter type list as it's list:
In this case foo is a int function that returns a double function, that returns a T. The param names i and d are optional, and ignored, except that i will be used in the function body. The label d is useless, but allowed for consistency. However, this is a valid type only in so far as the parser will recognize it. You cannot have a function return another function as part of a type. A '*' after the first would indicate an int function returning a pointer to double function, which is allowed.Code:T ((foo)(int i))(double d)
The type system will also allow mix and matching functions and arrays, always with the outer type closer to the name. So an array of functions would look like:
Again, you can't actually have that, only arrays of function pointers.Code:int ((array)[10])(int x);
Similarly a function returning an array:
This is also not allowed; functions can only return pointers to arrays.Code:int ((func(int x))[10]
That should give you enough information to answer your riddle. Otherwise the information is useless. If you ever actually work with nested combinations of functions and arrays, use a typedef for each contained or returned type, except multidimensional arrays.
Last edited by King Mir; 11-04-2011 at 06:22 AM.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
To follow up with King Mir, I find this site helpful when dealing with complex C declarations.
So technically, var=nullptr; or what? Var=? Translate into c language. Thx for help. I find very helpful the info. Im new in programming with so many pointers.
No, King Mir meant initialize the pointers (you basically have a 10x10 array of pointers) to null pointers, as in the null pointer constant NULL. That is one way, but that makes the pointers in your array fairly useless. If you want to fill them with something meaningful, you actually have to have something of the type they point to, i.e. the stuff in red:
thank you very much anduril462. You re page was very helpful. The answer wasEDIT: And thank you also King Mir.int *(*(**(*(**array[10][10])())())[])[];
Last edited by m3rik; 11-04-2011 at 12:40 PM.
I should have been paying more attention and noticed that it started with array of. Arrays are initialized with curly braces; you could initialize any array by putting equals curly braces at the end.
But I was sort of pointing out that the word you were looking for was definition not initialization. Initialization refers to giving a variable an initial value.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.