int main() {
char a;
char *str=&a;
strcpy(str,"hello");
printf(str);
return 0;
}
如有帮助,请采纳支持一下哦。点击我回答右上角【采纳】按钮。
能正常编译运行。
一般这么使用的:
#include<iostream>
#include<stdlib.h>
#include <cstring>
using namespace std;
int main() {
char a[30];
char *str=a;
strcpy(str,"hello");
printf(str);
return 0;
}
效果图:
虽然能输出hello,但不能正常运行,因为char a只能存1个字符,存"hello"会抛异常
a只是个字符,不是字符串