memcpy小用

#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

posted @ 2012-12-19 11:35  静心小阁  阅读(113)  评论(0编辑  收藏  举报