这样运行有错误吗?不可能呀
#include<stdio.h>
#include<string.h>
int main()
{
char s[] = "today", *p;
strcpy(p, s);
printf("%s\n", p);
return 0;
}
| 全能ASP/PHP/ASP.NET主机,支持月付 | 专业 MSSQL 数据库空间,支持月付 | 专业 MySQL 数据库空间,支持月付 | 学习型 ASP/PHP/ASP.NET 主机 30元/年 |
| 高端软件开发 = 年薪十万不是梦 | 赛孚耐:软件保护加密专家 | 身份认证令牌USB KEY |
这样运行有错误吗?不可能呀
#include<stdio.h>
#include<string.h>
int main()
{
char s[] = "today", *p;
strcpy(p, s);
printf("%s\n", p);
return 0;
}

#include "Stdio.h"
#include "string.h"
#include "stdlib.h"
#include "Conio.h"
int main()
{
char s[] = "today", *p;
p=(char *)malloc(sizeof(char)*(strlen(s)+1));
if(p==NULL)
exit(EXIT_FAILURE);
strcpy(p, s);
printf("%s\n", p);
free(p);
getch();
return 0;
}
没有为指针p分配空间.此时p是野指针。


*p指到哪里了啊??是不是没有赋值啊!!