Click here to Skip to main content
16,019,152 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#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
Posted
Updated 25-Oct-17 18:30pm
Comments
k5054 25-Oct-17 15:06pm    
You have z = x < 10 The expression (x < 10) is false, since x == 10. In C, False is zero, and True is Non Zero.

What did you expect the value of z to be?
Maciej Los 25-Oct-17 16:47pm    
My virtual 5!
Rajeesh_R 26-Oct-17 0:30am    
U are right.

1 solution

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).
 
Share this answer
 
Comments
Richard MacCutchan 26-Oct-17 4:52am    
Why have you copied someone else's answer and posted as if it is your solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900