【发布时间】:2023-04-09 21:32:01
【问题描述】:
我正在尝试编写一些 C 代码,在运行以下代码时,我的编译器在打印“A”后突然终止。为什么?
//report expected thing
void Expected(char *s){
int i=0;
int n = sizeof(s)/sizeof(s[0]);
while (i< n)
printf ("%c", s[i]);
printf(" expected.\n");
}
int main(int argc, char *argv){
printf("%c",65); //after this compiler hangs and asks for exit abnormally
char *Arr ={'a'};
Expected(Arr);
return 0;
}
另外,如果我把
char *Arr ={"a"}; //note the double quotes
然后它开始打印出无限数量的'a'。为什么会发生这种情况?
【问题讨论】:
-
你的编译器坏了。获得一个运行良好的新编译器。