As already mentioned, if you have a first pointer that points to some place in memory, and you assign bb = first , where bb is the type of compatible pointer, then bb points to the same address as first . This does not copy the contents of the memory referenced by first to the location referenced by bb . It copies the value of the pointer, which is the address, to bb .
If you define an array A , you cannot assign B = A to copy the contents of A to B You should use strcpy() or memcpy() or some such function. But the structures are different. You can assign the contents of one structure to a compatible structure.
In your example, bb and first are pointers to structures, and when you write bb = first , now both pointers refer to the same address in memory, and you no longer have access to the memory that bb originally referred to - now you have there is a memory leak! But *bb and *first are structures, and when you write *bb = *first , the contents of struct *first copied to struct *bb . So now you have two different structures in different places in memory, each of which has copies of the same three int s.
If your type my_struct contains a pointer to int , then after assigning *bb = *first each of them will contain a copy of the pointer to the same place in memory, but the data referenced by these pointers will not be copied. Thus, if the structures contain a pointer to an array, only the pointer will be copied, not the contents of the array, which will be divided by two structures.
source share