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.
- How to declare a pointer to a function?
- Why C treats array parameters as pointers?
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- 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
- Applications of Pointers in C/C++
- Features and Use of Pointers in C/C++
- Smart Pointers in C++
- Pointers and References in C++
- Pointers vs References in C++