[英]Please Explain why the Program output is 0 (programming in c)
Code: #include <stdio.h>代码:#include <stdio.h>
int main()
{
int x;
printf("%d\n",x);
if(x>10)
x-=10;
else if(x>=0)
x+=00;
else if(x)
x+=10;
else
x-=10;
printf("%d\n",x);
return 0;
}
Why initial value of x is zero?为什么 x 的初始值为零? what is the default value of int, float, double, char type data in c. c 中的 int、float、double、char 类型数据的默认值是多少? In this program x is assigned by default value or garbage value.在这个程序中 x 被分配默认值或垃圾值。
There is no default value in C. C 中没有默认值。 If a variable is uninitialized, it will have a random value.如果一个变量未初始化,它将有一个随机值。 In your case it seems to be 0 but it could be anything.在你的情况下,它似乎是 0,但它可能是任何东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.