[Solved] Printing pointer to pointer [closed]


You declared a as an array of int**, so *a is not a pointer to int but a pointer to pointer to int. Incrementing a pointer adds the size of the data type it points to, so ++*a advances the value at at a[0] by the size of a pointer.

What you actually stored in a[0] is a pointer to int, not a pointer to pointer to int. This is wrong and the compiler should have warned you about this. On your architecture it seems that a pointer is double the size of an int, so the increment ++*a adds the size of two ints to the pointer, so the value at a[0], if interpreted as int* instead of int **, skips over the 2.

To get the results you expect declare a as an array of int *.

int *a[2];

18

solved Printing pointer to pointer [closed]