Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
C++
#include <stdio.h>
#include <conio.h>
void main()
{
int a=5,b=10,c=15;


int d=a||b&&c;

printf("%d",d);
getch();
}


The output is true 1, but I do not understand how this output comes.
Posted
Updated 19-Oct-11 21:38pm
v2
Comments
André Kraak 20-Oct-11 3:39am    
DO NOT SHOUT when asking a question. When you use all capital letters it is seen as shouting on the Internet and considered rude. Next time when posting a question please use proper capitalization.

In C, any non-zero value is true, and only zero is false. So, when evaluating your expression (and ignoring precedence rules because they don't matter in this example)
true OR true AND true
will always be true. So a non-zero value will be returned. In this case, the C compiler returns 1 for true. Simples!
 
Share this answer
 
Comments
Albert Holguin 1-Nov-11 10:23am    
+5
|| and && consider any non zero as true
they are boolean oprators
 
Share this answer
 

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