为什么scanf在"int"的情况下给出最大值,但在超过限制的情况下在"char"的情况下崩溃程序?
#include<stdio.h>
main(){
int a;
char ch[10];
scanf("%d",&a);
printf("%d",a);
scanf("%s",ch);
printf("%s",ch);
}
Run Code Online (Sandbox Code Playgroud) 如果我们将c编程中的变量声明为整数而不定义值,则printf会从缓冲区中输出一些垃圾值.有没有办法防止打印垃圾值?
我想检查是否可以在编译时完成某些事情?如果可能的话?
有没有办法在不使用指针的情况下反向打印固定大小的字符串?
#include<stdio.h>
main()
{
char buffer[10];
scanf("%s", buffer);
// need to print buffer in reverse without using pointers??
}
Run Code Online (Sandbox Code Playgroud)