-
returning a pointer
I have been asked to write a function called merge that accepts
two pointers and returns a pointer.
So to define this I would write:
??? merge(LISTINTPTR *, LISTINTPTR *);
instead of the ??? what is the return type for a pointer?
like the two pointers that are being passed into the function, the pointer points to the first node of a linked list.
-
i would geuss LISTINTPTR* merge(LISTINTPTR* p1,LISTINTPTR* p2)
-
I'm pretty sure that that would give me an error/warning indicating a non recognisable return type.
What I'm asking is a general type like int or char, that is a return type used for pointers.
-
well if its an unrecognised return type then it is also an unrecognised parameter type!
-
pointers have no intrinsic type. You have to tell the compiler what type the pointer is to point to. An instance of a struct or class or a typedef are as valid a type as are the primitive types such int, char, etc.
In C lists are not much more than a pointer to a struct that contains (a) data member(s) and a pointer to the type. In C++ lists are frequently elevated to types in and of themselves containing not only the data member(s) and pointer(s) but the functions necesarray to manipulate information contained in the list.