I am trying to figure out how pointer arithmetics work on arrays. However I couldn't make an example work.
Firstly I start with a one dimensional array and the example works;
Code:
#include <stdio.h>
int main(void){
int array[2];
int *ptr=array;
*(ptr+1)=1000;
printf("%d",array[1]);
return 0;
}
After that I add one more dimension and it doesn't show the result I want;
Code:
#include <stdio.h>
int main(void){
int array[2][2];
int (*ptr)[2]=array;
*(ptr+1)=999;
printf("%d",array[1][0]);
return 0;
}
Why doesn't this increase the address by one *ptr[2]? Isn't it possible to perform pointer arithmetics with pointer to arrays?