oadams
oadams

Reputation: 3087

Finding the size of a pointer

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

This line results in a syntax error because of the *. What should I do to get it to work?

Upvotes: 2

Views: 311

Answers (2)

shuttle87
shuttle87

Reputation: 15924

You are currently trying to find out the size that is at address void. If you are looking to find the size of a void pointer perhaps try: sizeof(void*) instead.

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

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

Edit: Something else that I just thought of for the first time, is %zu compiler dependent? Do we need to do things differently on 32bit or 64bit architecture?

Upvotes: 9

Marcelo Cantos
Marcelo Cantos

Reputation: 185852

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

Upvotes: 6

Related Questions