I have a pointer as follows:
int val2 = 90;
int *p = &val2;
Then, I do:
int *pp = &p; // Line 3
The Line 3 is illegal. I know it should have written int **pp = &p, but I dont understand why. Is that the address of a normal variable different with the address of a pointer?
int *ppdefinesppas a pointer to anint, but you’re trying to initialize it with the address of a pointer to anintinstead of the address of anint. Since “address of an int” and “address of a pointer to an int” don’t have the same type, the compiler won’t let you do this (at least without a cast, though you almost certainly don’t want to do that).Yes, the two types of pointers are probably the same size, so the CPU could move the data from one location to another without any real problem. The compiler, however, does type checking to help keep you from shooting yourself in the foot, and that’s what it’s doing here. It’ll let you do what you’re asking with the cast mentioned above, but since what you’re doing makes little or no sense, you need to use a cast if you really insist on doing it.