解释这件code的输出的本质是什么? [英] Explain about the nature of output of the code?

查看:77
本文介绍了解释这件code的输出的本质是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code:

#include<stdio.h>
int main(void)
{
  int i, j;
  for(j = i+1, i=1; i<=5; j++, i++)
     printf("%d %d\n", i, j);
  return 0;
}

输出:

1 66
2 67
3 68
4 69
5 70

有关code的输出的性质任何人都可以解释一下吗?

Can Anyone explain about the nature of output of the code?

推荐答案

在您的code I Ĵ在声明时不被初始化。结果
在fo​​r循环分配 J = + 1 那么Ĵ仍垃圾的价值,而 I 分配 1

In your code i, j are not initialized at the time of declaration.
In for loop you assign j = i + 1 So j remains garbage value whereas i assigned 1 ,

在for循环中你增加 I Ĵ和printf值。 I 1 增量 5 从最初的垃圾值(即66的输出)>初始垃圾+ 5

in for loop you increment i, j and printf values. i increment from 1 to 5, and j from a initial garbage value (that is 66 in your output) to initial garbage + 5.

修改在意见的基础:

如果您不分配在声明中初始值的变量将可能包含previously 地址指向从另一个应用程序使用的数据(或最后一次使用)。

If you don't assign an initial value upon declaration the variable will be pointing at an address that may contain previously used data from another application(or any last used).

在运行系统中分配内存分配之前不清除内存之前(的只是为了保持系统的高性能的)因此,该变量的默认值是垃圾值。

Before allocating memory in runtime system does not clear the memory before allocating (just to keep system performance high) So,default value of the variable is garbage value.

这篇关于解释这件code的输出的本质是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆