【C语言】一些简单编译错误或警告
1. [Warning] ‘s’ is used uninitialized in this function [-Wuninitialized]
错误代码
#include <stdio.h>
int main(){
char *s;
scanf("%3s",s);
printf("%s",s);
return 0;
}
正确代码
#include <stdio.h>
int main(){
char s[100];
scanf("%3s",s);
printf("%s",s);
return 0;
}
以下代码也是正确的。
char *s;
s="ABCDE";
错误原因
没有给s分配内存空间,如果要使用char *s的话,需要先进行赋值如char *s="hello world"
本文来自博客园,作者:Fannnf,转载请注明原文链接:https://www.cnblogs.com/overtop/p/15890754.html

浙公网安备 33010602011771号