指针的赋值问题,为毛可以编译却不可以运行...
#include<string.h>#include<iostream.h>
void main()
{
char buffer[10];
strcpy(buffer,"ABC");
cout<<buffer<<endl;
char *ps;
ps="hello";
cout<<ps<<endl;
strcpy(ps,buffer);
cout<<buffer<<endl;
}
运行的时候弹对话框,
指针的位置问题重叠?
#include "stdafx.h" #include<string.h> #include<iostream.h> void main() { char buffer[10]; strcpy(buffer,"ABC"); cout<<buffer<<endl; char *ps; ps="hello"; cout<<ps<<endl; //strcpy(ps,buffer); 这句出错 //ps变量保存的为"hello", "hello"是常量 //strcpy(ps,buffer); 这句修改了常量 //编译器的语法检查常量是不可以修改的,所以弹出错误框 strcpy(ps,buffer); cout<<buffer<<endl; }