Whats the meaning of this code

Discussion in 'C++' started by sam, Jan 24, 2007.

  1. sam

    sam Guest

    HI,
    The code is as follows:-

    #include <stdio.h>
    1
    2 void * work(void * ptr)
    3 {
    4 int i;
    5 for (i = 0; i < 10; i++)
    6 {
    7 printf("%d", (int)ptr);
    8 usleep(1000);
    9 }
    10 return 0;
    11 }

    Whats the meaning of this line:-
    void *work(void *ptr)
    sam, Jan 24, 2007
    #1
    1. Advertising

  2. sam

    Noah Roberts Guest

    On Jan 24, 8:34 am, "sam" <> wrote:
    > HI,
    > The code is as follows:-
    >
    > #include <stdio.h>
    > 1
    > 2 void * work(void * ptr)
    > 3 {
    > 4 int i;
    > 5 for (i = 0; i < 10; i++)
    > 6 {
    > 7 printf("%d", (int)ptr);
    > 8 usleep(1000);
    > 9 }
    > 10 return 0;
    > 11 }
    >
    > Whats the meaning of this line:-
    > void *work(void *ptr)


    Though this is valid C++ the techniques are used more often in C. The
    use of the stdio.h header also indicates C. If you're coding in C
    you'll want to go to that newsgroup. We'll tell you not to write code
    like that.

    The meaning...a function called work that accepts a pointer of type
    void (basically meaninng "whatever") and returns the same.
    Noah Roberts, Jan 24, 2007
    #2
    1. Advertising

  3. sam

    red floyd Guest

    sam wrote:
    > HI,
    >[code redacted]
    >
    > Whats the meaning of this line:-
    > void *work(void *ptr)


    Noah answered your question, but my question is,

    What book are you reading that does not explain function declarations?
    red floyd, Jan 24, 2007
    #3
  4. sam

    Jim Langston Guest

    "sam" <> wrote in message
    news:...
    > HI,
    > The code is as follows:-
    >
    > #include <stdio.h>
    > void * work(void * ptr)


    This is defining a function named work which returns a void* (pointer to
    type void) and receives as a parameter a variable named ptr which is a void*
    (pointer to type void).

    > {
    > int i;
    > for (i = 0; i < 10; i++)
    > {
    > printf("%d", (int)ptr);
    > usleep(1000);
    > }
    > return 0;
    > }
    >
    > Whats the meaning of this line:-
    > void *work(void *ptr)
    >
    Jim Langston, Jan 24, 2007
    #4
    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. Noah Roberts

    Re: Whats the meaning of this code

    Noah Roberts, Jan 24, 2007, in forum: C Programming
    Replies:
    5
    Views:
    400
    santosh
    Jan 24, 2007
  2. sam
    Replies:
    3
    Views:
    278
    Ron Natalie
    Jan 30, 2007
  3. sam
    Replies:
    5
    Views:
    607
    Victor Bazarov
    Apr 23, 2007
  4. sam
    Replies:
    4
    Views:
    349
    gtkmm
    Sep 6, 2008
  5. Replies:
    4
    Views:
    755
Loading...

Share This Page