[Solved] Why pointer of pointers are declared with different no. of asterisk when their size is same [closed]


No it matters. Pointer arithmetic solely depends on what it points to. For example int(*p)[2] and int *p both of them are different. The same way int **p and int ***p is different. You might think even if the sizeof (int*) and sizeof(int**) is same – it is not logical to lose the multiple indirection information. It is helpful for having correct pointer arithmetic. (And in case their size same it will be same but pointer arithmetic will be no problem but it will be problematic in other way – see second para for the problem).

Note these are quite helpful for us to write – think of a system where you will have the responsibilty of writing the correct code for dereferencing the variable correct number of times. You have to keep in mind the where it points to? whether it’s an address of a variable or pointer to a pointer. This will simply make C programming nothing other than writing down in the underlying assembly language – where we will have to deal with raw addresses. And then think, to remember how many times you need to dereference you need to maintain some metadata along with that variable – precisely what are being stored by compiler by preserving the type information int* or int**.

4

solved Why pointer of pointers are declared with different no. of asterisk when their size is same [closed]