This is what I'm trying to achieve. Inside pointer 'r' I have the address of pointer 'p', now I try to move the value of 'p'(which is an address) using pointer arithmetic by calling function moveforward(). I get this error :
void value not ignored as it ought to be
movingresult=moveforward(r);
What's wrong here? It's a bit complicated though dealing with pointer to pointer.
#include <stdio.h>
void moveforward(int** y) {
*y = *y+1;
printf("value of *y in function : %p\n",*y);
}
int main () {
int a = 16;
int *p;
int **r;
p = &a;
r = &p;
int **movingresult;
printf("Value of p before moving :%p\n",p);
movingresult=moveforward(r);
printf("Value of p after moving :%p",movingresult);
return 0;
}
I just changed my code , so now it looks like this, everything runs well , but the result is not what i expected.
#include <stdio.h>
void moveforward(int** y) {
*y = *y+1;
printf("Value of *y now has been moved to : %p\n",*y);
}
int main () {
int a = 16;
int *p;
int **r;
p = &a;
r = &p;
int **movingresult;
printf("Value of p before moving :%p\n",p);
moveforward(r);
printf("Value of p after moving :%p\n",r);
return 0;
}
OUTPUT :
Value of p before moving :0x7fffa5a1c184
Value of *y now after moving : 0x7fffa5a1c188
Value of p after moving :0x7fffa5a1c178
MY EXPECTATION : the 'p' after moving must be equal to *y which is 0x7fffa5a1c188


moveforwardis declaredvoid.main.c: In function 'main': main.c:19:13: error: void value not ignored as it ought to be movingresult=moveforward(r); ^ exit status 1printf("Address of p after moving :%p\n",r);-->printf("Address of p after moving :%p\n", p);orprintf("Address of p after moving :%p\n",*r);