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 Drew, I am new to C and forum posts such as this void pointer one help me learn. I searched the web for C99 and did find some examples so at least understand what it is. I will use some bits of it from now on. But at my present level of C knowlewdge will not try to do more than this.

    I am struggling with multi-dimensional char arrays, pointer etc right now and am getting some odd results, but I will persevere!

Reply
  • Thanks Drew, I am new to C and forum posts such as this void pointer one help me learn. I searched the web for C99 and did find some examples so at least understand what it is. I will use some bits of it from now on. But at my present level of C knowlewdge will not try to do more than this.

    I am struggling with multi-dimensional char arrays, pointer etc right now and am getting some odd results, but I will persevere!

Children