Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 以下程序的输出是什么?_C_Loops - Fatal编程技术网

C 以下程序的输出是什么?

C 以下程序的输出是什么?,c,loops,C,Loops,当问题得到解决时运行该问题,终止循环 #include<stdio.h> #include<conio.h> void main() { int n=12,res=1; clrscr(); while(n>3) { n+=3; res*=3; } printf("%d",n*res); getch(); } #包括 #包括 void main() { int n=12,res=1; clrsc(); 而(n>3) { n

当问题得到解决时运行该问题,终止循环

#include<stdio.h>
#include<conio.h>
void main()
{
  int n=12,res=1;
  clrscr();
  while(n>3)
  {
    n+=3;
    res*=3;
  }
  printf("%d",n*res);
  getch();
}
#包括
#包括
void main()
{
int n=12,res=1;
clrsc();
而(n>3)
{
n+=3;
res*=3;
}
printf(“%d”,n*res);
getch();
}

以上结果为3595。但我不明白while循环的过程。当它获取并终止其循环时?

代码的行为是未定义的,因为您最终将溢出一个
有符号的
整数类型

因此,输出可以是任何东西


(在您的例子中,
n
似乎是一个负数,因此
n>3
条件不再是
true
。但是不要依赖此行为:例如,某些体系结构将钳制
n

学习。C不是C++。你的循环是错误的,
n
总是优于3,直到它溢出为止!正如程序所说,它是无效的,任何关于它的行为的讨论都是没有意义的。