长度为0的数组
/*
* size_0_test.c
*
* Created on: 2012-2-23
* Author: root
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct line{
int length;
char contents[0];
};
int main(){
struct line *l =(struct line *) malloc(sizeof(struct line)+8);
char message[10]="hello";
strcpy(l->contents,message);
printf("size of line is :%s.\n",l->contents);
return 0;
}
c语言中长度为0的字符数组不占用长度。用来支持变长数组。