void pointer

Discussion in 'C Programming' started by janus, Dec 26, 2009.

  1. janus

    janus Guest

    Hello All,

    I am aware that void pointer (or generic pointer) could be use in
    function arguments and as the return type of a function.

    void * swap1(void * lpr1, void * lpr2,...);

    Is there any other place it may be used? If yes, please give
    examples.

    Regards,
    Janus
    janus, Dec 26, 2009
    #1
    1. Advertising

  2. janus

    Nick Guest

    janus <> writes:

    > Hello All,
    >
    > I am aware that void pointer (or generic pointer) could be use in
    > function arguments and as the return type of a function.
    >
    > void * swap1(void * lpr1, void * lpr2,...);
    >
    > Is there any other place it may be used? If yes, please give
    > examples.


    This smells slightly like a homework problem. But the answer is that it
    may be used anywhere you are keeping or transferring a pointer without
    dereferencing it. To and from a function is an obvious such place, but
    inside a storage container of some sort is another.

    Example:

    char *p;
    void *q = p;
    char *w = q;

    That's pointless, but you asked about "may", not "may usefully"...
    --
    Online waterways route planner: http://canalplan.org.uk
    development version: http://canalplan.eu
    Nick, Dec 26, 2009
    #2
    1. Advertising

  3. janus

    janus Guest

    Nick,

    I am not a student, I am just trying to learn C on my own. Thanks so
    much.

    Regards,
    Janus

    On Dec 26, 12:59 pm, Nick <> wrote:
    > janus <> writes:
    > > Hello All,

    >
    > > I am aware that void pointer (or generic pointer) could be use in
    > > function arguments and as the return type of a function.

    >
    > > void * swap1(void * lpr1, void * lpr2,...);

    >
    > > Is there any other place it may  be used? If yes, please give
    > > examples.

    >
    > This smells slightly like a homework problem.  But the answer is that it
    > may be used anywhere you are keeping or transferring a pointer without
    > dereferencing it.  To and from a function is an obvious such place, but
    > inside a storage container of some sort is another.
    >
    > Example:
    >
    > char *p;
    > void *q = p;
    > char *w = q;
    >
    > That's pointless, but you asked about "may", not "may usefully"...
    > --
    > Online waterways route planner:http://canalplan.org.uk
    >            development version:http://canalplan.eu
    janus, Dec 27, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ollej Reemt
    Replies:
    7
    Views:
    499
    Jack Klein
    Apr 22, 2005
  2. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    775
    The Real OS/2 Guy
    Oct 28, 2003
  3. Replies:
    5
    Views:
    815
    S.Tobias
    Jul 22, 2005
  4. Hakirato
    Replies:
    4
    Views:
    859
    Alf P. Steinbach
    Oct 5, 2006
  5. Replies:
    1
    Views:
    392
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page