#include <stdio.h> #include <string.h> struct str1{ int a; int b; int c; int d; }; main() { struct str1 aa = {1,2,3,4}; struct str1 bb; memset(&bb,0x00,sizeof(struct str1)); memcpy(&bb.b, &aa.b, sizeof(int) * 3); printf("%d\n", bb.a); printf("%d\n", bb.b); printf("%d\n", bb.c); printf("%d\n", bb.d); }
result:
0
2
3
4