本文共 639 字,大约阅读时间需要 2 分钟。
柔性数组验证代码
#include <stdio.h>
#include <malloc.h> //must add // #include <stdlib.h>typedef struct test //must add typedef else error !!!!
{ int a; float b; char c[]; }ts; void ti() { struct test *i; int k; // apply for memory.. i = (struct test *)malloc(sizeof(struct test)+ 100*sizeof(char)); i->a=40; // i.a=50; //close .cannot be used. i->b=9; //i->c= "k" ; #if 1 for(;k<10;k++) { i->c[k]=k; printf("k is %d\n",i->c[k]); } #endif printf(" size value is : %d\n", sizeof (*i)); printf("p->a value is : %d\n", i->a ); printf("i->b value is : %f\n", i->b ); free(i); //free the memory !!! }int main()
{ti(); //call the function
return 0; }
转载地址:http://ydtgf.baihongyu.com/