Q:

trouble printing pointers to void on structure

#include <stdio.h>

typedef struct elem{

    void * d;

}Elem;

main(){

    Elem *p;
    Elem e;

    double pi = 3.14;

    e.d = &pi;
    p->d = &pi;

    printf("%f\n",p->d);
    printf("%f\n",e.d);

}

main.c:25: warning: format ‘%f’ expects type ‘double’, but argument 2 has type ‘void *’
main.c:26: warning: format ‘%f’ expects type ‘double’, but argument 2 has type ‘void *’
I'm having trouble trying to print this values correctly.
I'm getting values that got nothing to do with 3.14.

A:

In your code, first, you need to allocate memory to p before dereferencing it. Otherwise, it invokes undefined behavior. Otherwise, p is an unitialized pointer and points to a memeory, which may not be accessible from your program, thereby, essentially, an invalid memory location. Any attempt to dereference that pointer will invoke UB.
After that, 
  printf("%f\n",p->d);
  printf("%f\n",e.d);

invokes undefined behavior, as you're essentially trying to print an address with %f format specifier.
What you have to do, is to 

cast the void pointer to float pointer (beacuse, you cannot dereference a void *) 
and then, derererence the pointer to get the value.

Like
  printf("%f\n",*((float *)(p->d)));
  printf("%f\n",*((float *)e.d));    

That said, main() should be int main(void), at least, to be standard complaint.

