分类: C/C++
2018-12-12 16:19:31
#includestruct Test { int len; char data[0]; }; int main() { char str[] = "abc"; Test* t = (Test*)malloc(sizeof(struct Test) + sizeof(str)); t->len = sizeof(str); memcpy(t->data, str, sizeof(str)); printf("len: %d\n", t->len); printf("data: %s\n", t->data); free(t); }