strcpy应该注意的问题

来源:互联网 发布:java接口时间记录 编辑:程序博客网 时间:2024/05/01 18:14

1.char* a = "test";中a中存的值不能改,如*a  = 'a';就会报错,所以下面这么做会出错

#include<iostream>int main(){char *a = "k";char b[5]= "test";strcpy(a,b);//a中的值不可修改std::cout<<b;system("pause");}


2.strcpy不接受NULL指针,如

#include<iostream>int main(){char *a = NULL;char b[5]= "test";strcpy(b,a);//不接受NULL指针std::cout<<b;system("pause");}


 

原创粉丝点击