Bootstrap

C结构体 直接赋值及 memcpy

一、C结构体可直接 赋值

二、C结构体可memcpy()


#include <stdio.h>
#include <string.h>


typedef struct mystruct
{
    int a;
    short b;
    char sh[16];
}mystruct_T;




int main(int argc, const char *argv[])
{   
    mystruct_T st1, st2;
    mystruct_T *pst;


    char cc[128];


    memset(cc, 0, sizeof(cc));


    st1.a = 1;
    st1.b = 1;
    strcpy(st1.sh, "hello body");
    
    memset(&st2, 0, sizeof(mystruct_T));


    printf("st1.a = %d\n", st1.a);
    printf("st1.b = %d\n", st1.b);
    printf("st1.sh: %s\n", st1.sh);
    
    printf("---------------------\n");
    printf("st2.a = %d\n", st2.a);
    printf("st2.b = %d\n", st2.b);
    printf("st2.sh: %s\n", st2.sh);


    st2 = st1;
    printf("====================\n");
    printf("st2.a =
;