Find pointer size

printf("pointer: %d\n", sizeof(*void));

      

This line results in a syntax error due to *. What should I do to make it work?

+2


a source to share


2 answers


You are currently trying to figure out the size, which is at void. If you want to find the size of a void pointer try: sizeof (void *).

printf("pointer: %zu\n", sizeof(void*));

      



should do what you want. Use% zu, not% d, as the pointer is an unsigned value, not a decimal value.

Edit: Is there something else that I just thought of the first time around depends on the% zu compiler? Do I need to do something differently on a 32-bit or 64-bit architecture?

+9


a source


printf("pointer: %d\n", sizeof(void*));

      



+6


a source







All Articles