Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sizeof void pointer

Tags:

why is sizeof void pointer 2 ?

like image 249
alfesani Avatar asked Oct 04 '10 07:10

alfesani


People also ask

Why is sizeof void 1?

When you do pointer arithmetic adding or removing one unit means adding or removing the object pointed to size. Thus defining sizeof(void) as 1 helps defining void* as a pointer to byte (untyped memory address).

What size is void * in 32-bit?

In a 32-bit system, the size of a void pointer is 4 bytes.

What is the sizeof a pointer?

On 32-bit machine sizeof pointer is 32 bits ( 4 bytes), while on 64 bit machine it's 8 byte. Regardless of what data type they are pointing to, they have fixed size.

What is the value of void pointer?

The null pointer is basically used in a program to assign the value 0 to a pointer variable of any data type. The void pointer, on the other hand, has no value assigned to it and we use it to store the addresses of other variables in the program- irrespective of their data types.


1 Answers

The size of a void* is a platform dependent value. Typically it's value is 4 or 8 bytes for 32 and 64 bit platforms respectively. If you are getting 2 as the value then your likely running on a 16 bit coding platform (or potentially have a coding error).

Could you post the code you are using and some more information about your environment / operating system?

like image 82
JaredPar Avatar answered Jan 02 '23 19:01

JaredPar