You are misleading the expression and purpose.
*a = *b is called assignment. Note that it does not include the type name.
int *a = &x , on the other hand, is called a declaration. Note that you are initializing the pointer with address x. You are not looking for a pointer, but declaring it as a pointer to an int.
Look at this:
int main() { int a = 5; int b = 2; int *c = &a; // c when dereferenced equals 5; **Declaration** int *d = &b; // d when dereferenced equals 2; **Declaration** int tmp = *c; // tmp equals 5 *c = *d; // c when dereferenced now equals 2 **Assignment** *d = tmp; // d when dereferenced now equals 5 **Assignment** return 0; }
Finally, when you declare and initialize the pointer in the same expression, you assign the address of the pointer that you want to point to it. When you want to change the value that the object points to, you cast it with * . On the other hand, if you want to change what it points to, you will not find it.
Isaiah
source share