Question: I am not able to execute pthreads program in c. Please tell me what is wrong with the following program. I am neither getting any error nor expected output.

```
void *worker(void * arg)
{
  int i;
  int *id=(int *)arg;
  printf("Thread %d starts\n", *id );
}

void main(int argc, char **argv)
{
  int thrd_no,i,*thrd_id,rank=0;
  void *exit_status;
  pthread_t *threads;

  thrd_no=atoi(argv[1]-1);

  thrd_id= malloc(sizeof(int)*(thrd_no));
  threads=malloc(sizeof(pthread_t)*(thrd_no));

  for(i=0;i<thrd_no;i++)
  {
    rank=i+1;
    thrd_id[i]=pthread_create(&threads[i], NULL, worker, &rank);
  }

  for(i=0;i<thrd_no;i++)
  {
    pthread_join(threads[i], &exit_status);
  }
}

```

Answer: 
`thrd_no = atoi(argv[1] - 1);` likely doesn't do what you intended; the way `argv` is normally passed into a new process and parsed into a C array, `argv[1] - 1` is probably pointing at `\0` (specifically, the `\0` at the end of `argv[0]`). (More generally, indexing backwards off the start of a string is rarely correct.) The result is that `atoi()` will return 0 and no threads will be created. What did you actually intend to do there?
You are passing the same address `&rank` to each thread, so `id` and `*id` is the same for all your `worker`-s.

You should better allocate on the heap the address you pass to each worker routine. 

You might also include `<stdint.h` and use `intptr_t`, e.g.

```
 void worker (void* p)
 {
    intptr_t rk = (intptr_t) p;
    /// etc
 }

```

and call 

```
intptr_t rank = i + 1;
thrd_id[i]=pthread_create(&threads[i], NULL, worker, (void*)rank);

```

You should **learn to use a debugger** and **compile with all warnings and debug information**, i.e. `gcc -Wall -g` (and improve your code till it gets no warnings, then use `gdb`)