Whats the meaning of this code

S

sam

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)
 
N

Noah Roberts

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

red floyd

sam said:
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?
 
J

Jim Langston

sam said:
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top