Why you can’t dereference a void* pointer

Why you can't dereference avoid pointer

The compiler will not let you dereference avoid pointer because it does not know the size of the object pointed to. If the pointer points to a char, which is one byte, the compiler needs to access only that one byte; if the
pointer points to a double, not only is there more memory that needs to be accessed, but the layout is very different since it is represented as a floating point number.

You can of course use avoid, and it's very handy for writing generic code in C without templates, but you need to typecast your pointer to the right type before you dereference it.

So, Why you can't dereference avoid pointer …. You know it now.

Feel free to ask something or to comment.

  • Article By :

Random Posts

Leave a Reply