Thread: returning a pointer

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4

    Question 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.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    i would geuss LISTINTPTR* merge(LISTINTPTR* p1,LISTINTPTR* p2)
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4
    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.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    well if its an unrecognised return type then it is also an unrecognised parameter type!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. Another Linked List plee
    By Dragoncaster131 in forum C Programming
    Replies: 3
    Last Post: 05-15-2004, 05:40 PM
  5. returning pointer to string between exe and dll
    By evilpope in forum C Programming
    Replies: 2
    Last Post: 05-15-2003, 12:16 PM