【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"


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM