69,381
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
struct helloworld_t
{
int num;
char helloworld[0];//主要是用来得到一个数组的地址,再由数组的个数来访问
};
int main()
{
struct helloworld_t *p;
unsigned int size = sizeof(struct helloworld_t) + strlen("Hello World!\n") + 1;
p = (struct helloworld_t *) malloc(size);
assert(p!=NULL);
memcpy(p, "\x01\x00\x00\x00Hello World!\n", size);//\x01\x00\x00\x00四字节,就是给num赋值
//在内存中高8位和低8位反一下...
// printf("%d\n",p->num);
while (p->num--)
{
printf(p->helloworld);
}
//printf("%d \n", sizeof(helloworld_t));
free((void *)p);
return 0;
}