#include "stdio.h" #include "stdlib.h" struct Teacher { int age; char name[]; }; char *getMemory4(int memorySize) { struct Teacher *pTmp = NULL; pTmp = (struct Teacher *)malloc(memorySize * sizeof(struct Teacher)); char *cVar = NULL; cVar = (char *)malloc(memorySize * sizeof(struct Teacher)); return cVar; } int main() { return 0; }
VC++ 6.0 报错如下:
VS2010 报错如下:
经测试: 当注释掉函数中的
struct Teacher *pTmp = NULL; pTmp = (struct Teacher *)malloc(memorySize * sizeof(struct Teacher));
这两行时刻正常运行......实在是有点疑惑?
大神们怎么看?勿喷,谢谢!
已解决!!!!C语言不能在函数中间定义变量!
为什么我的vc++6.0没有报错 就你最初的源码 也没看出你的代码有什么出错的地方
然而还是这样子: 不科学啊!!