是关于存储类的,你自己去参见文件,就知道啦
看到那么多人都说要用malloc都得包含<alloc.h>
叹口气先
建议大家还是尽量用标准c
要用malloc的时候还是包含<stdlib.h>文件吧
代码调试观察str值:
void main()
{
char *str=NULL; // 0x00000000
display(str);
printf("%s",str);
}
void display(char *str)
{
str=(char *)malloc(100); //0x00372928
str="gskgshdfh"; //0x00422020
printf("%s",str); //screen:"gskgshdfh"
free(str); //此处死掉
//debug in,死因在_CRTIMP void __cdecl _free_dbg中,如下:
/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
// _ASSERTE(_CrtIsValidHeapPointer(pUserData));
getch();
}
所以和楼上的意见相同,同iFreeBSD的有出入.呵呵,估计是编译器的原因吗?应该不会.稍后用GCC试试.