为什么变量z的值= 0? [英] Why is the value of variable z = 0 ?

查看:105
本文介绍了为什么变量z的值= 0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>

int main()

{

int x = 3,y,z;

y = x = 10;

z = x< 10;

printf(x =%d \\\
y =%d \ nn =% d \ n,x,y,z);



getch();

}



我尝试过:



输出是

x = 10 y = 10和z = 0



为什么z = 0 ??



a概念问题

#include<stdio.h>
int main()
{
int x=3,y,z;
y=x=10;
z=x<10;
printf("x=%d\n y=%d\n z=%d\n",x,y,z);

getch();
}

What I have tried:

output is
x=10 y=10 and z=0

why is z =0 ??

a conceptual problem

推荐答案

你期望z的价值是什么?!!!

Maciej Los的答案完全相同。



x = 10,因此表达式x <10评估为FALSE。由于z是int的类型,因此赋值给它的值为零(相当于FALSE)。
What did you expect the value of z to be then?!!!
Exactly the same answered by Maciej Los.

x=10, so the expression x<10 evaluate to FALSE. Since z is a type of int, the value assigned to it is zero(equivalent to FALSE).


这篇关于为什么变量z的值= 0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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