C++溢出问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 23:23:19
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
void copy(char *input)
{
char var[10];
strcpy(var,input);
}
int main(int argc, char* argv[])
{
char source[]="abcdefghijklmnopqrstuvwxyz";
copy(source);
return 0;
}
程序运行后会出现什么?为什么呢?

strcpy(var,input);

由于你传入了长度大于10的字符串,
copy过程中会访问非法内存区域,异常退出

C++溢出问题
悬赏分:5 - 离问题结束还有 14 天 21 小时
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
void copy(char *input)
{
char var[255];
strcpy(var,input);
}
int main(int argc, char* argv[])
{
char source[]="abcdefghijklmnopqrstuvwxyz";
copy(source);
return 0;
}