This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

void pointer behaviour ?

Hi,
I observed a strange behaviour (for me only) of void pointer. I wrote a code to access an integer through void pointer as below:

void *ptr;
int a[2] = {1,2};

ptr = (int *)&a;
ptr++; // This is giving error: Unknown Size

Why the above increment statement is giving error as i already cast the pointer to int type ?

Can anybody help me in understanding this ?

Karthik K.

Parents
  • Thanks Neil for your suggestion.
    I know the basic of C, but some miscellaneous concept like void pointer, null pointer, dangling pointer,etc.. will not be explored in most of the book. Generally C book gives the basic programming guide, not the in depth knowledge. Or may be but i am not aware of such book.

    If any one have idea then please let me know.

Reply
  • Thanks Neil for your suggestion.
    I know the basic of C, but some miscellaneous concept like void pointer, null pointer, dangling pointer,etc.. will not be explored in most of the book. Generally C book gives the basic programming guide, not the in depth knowledge. Or may be but i am not aware of such book.

    If any one have idea then please let me know.

Children
No data