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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to declare a pointer to a function?
- Pointer to an Array | Array Pointer
- Different ways to declare variable as constant in C and C++
- What is a Pointer to a Null pointer
- std::tuple, std::pair | Returning multiple values from a function using Tuple and Pair in C++
- Passing and Returning Objects in C++
- Why C treats array parameters as pointers?
- Pointers in C and C++ | Set 1 (Introduction, Arithmetic and Array)
- Sum of array using pointer arithmetic
- What are Wild Pointers? How can we avoid?
- Introduction of Smart Pointers in C++ and It's Types
- Dangling, Void , Null and Wild Pointers
- Pointers in C/C++ with Examples
- Pointers vs References in C++
- Computing index using pointers returned by STL functions in C++
- Applications of Pointers in C/C++
- How to implement user defined Shared Pointers in C++
- Features and Use of Pointers in C/C++
- Pointers and References in C++
- Difference between Iterators and Pointers in C/C++ with Examples