If instead of copying all bytes in A, you only copy the number of bytes that B expects, you will achieve your desired result:
memcpy(&v2, &v1, sizeof(v2)); // remember that the first argument is the destination
However, this is not good coding style. With this minimal code example, it is hard to tell, but you would probably want A to inherit from B so that you can convert the two without having to physically copy memory.
Otherwise, this would be easier and cleaner:
b2.a = v1.a;
4
solved Copy structure to a different structure [closed]