I don't get why the last snippet of code prints 2000 and not 4000. Some beginner error I guess. Do you know? Using DevC++.
int val1 = 1000;
int val2 = 2000;
int val3[2] = {3000, 4000};
int **b[3];
*(b+0)= &val1;
*(b+1) = &val2;
*(b+2) = &val3;
//Prints 1000
//Prints what the first element of b is pointing at
printf("%d\n",b[0][0]);
printf("%d\n",**(b+0) );
//Prints 2000
printf("%d\n", b[1][0] );
printf("%d\n",**(b+1) );
//Prints 3000
printf("%d\n", b[2][0] );
printf("%d\n", **(b+2) );
//Should print 4000 i think, but prints 2000, why?
printf("%d\n", b[2][1] );
printf("%d\n", *(*(b+2)+1) );
EDIT: What I wanted was **b to be a pointer to an array or pointers, but I guess what happened is that I made **b an array of pointers-to-pointers instead.
Below in the answers are great solutions for the code to work in one way, and here is a solution for how to make the code work as I originally intended: