柔性数组问题
#include <iostream>using namespace std;
struct MyData
{
int nLen;
char data[0];
};
int main()
{
int nLen = 10;
char str[10] = "123456789";
cout << "Size of MyData: " << sizeof(MyData) << endl;
MyData *myData = (MyData*)malloc(sizeof(MyData) + 10);
memcpy(myData->data, str, 10);
cout << "myData's Data is: " << myData->data << endl;
free(myData);//这个free能把申请的14个字节的内存free掉吗?会内存泄漏啊?
return 0;
}