Declare “a function with argument of int* which returns pointer to an array of 4 integer pointers”.
At the first glance it may look complex, we can declare the required function with a series of decomposed statements.
1. We need, a function with argument int *,
2. a function with argument int *, returning pointer to
3. a function with argument int *, returning pointer to array of 4
4. a function with argument int *, returning pointer to array of 4 integer pointers
int *(*function(int *));
How can we ensure that the above declaration is correct? The following program can cross checks our declaration,
The macro SIZE_OF_ARRAY is used for symbolic representation of array size. p_array_t is typedefined as “pointer to an array of 4 integers”. If our declaration is wrong, the program throws an error at the ‘function‘ definition.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- How to declare a pointer to a function?
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Why C treats array parameters as pointers?
- Pointer to an Array | Array Pointer
- Sum of array using pointer arithmetic
- Different ways to declare variable as constant in C and C++
- std::tuple, std::pair | Returning multiple values from a function using Tuple and Pair in C++
- Passing and Returning Objects in C++
- What is a Pointer to a Null pointer
- Input an integer array without spaces in C
- Pointers in C/C++ with Examples
- Pointers vs References in C++
- Pointers and References in C++
- Features and Use of Pointers in C/C++
- Applications of Pointers in C/C++