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?
- Different ways to declare variable as constant in C and C++
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Why C treats array parameters as pointers?
- std::tuple, std::pair | Returning multiple values from a function using Tuple and Pair in C++
- Pointer to an Array | Array Pointer
- Sum of array using pointer arithmetic
- Passing and Returning Objects in C++
- Input an integer array without spaces in C
- Smart Pointers in C++
- Applications of Pointers in C/C++
- Pointers in C/C++ with Examples
- Pointers vs References in C++
- What are Wild Pointers? How can we avoid?
- How to implement user defined Shared Pointers in C++