 Help me understand the output of this code #include <stdio.h> int main() { int x=2; int y=5; printf("%d",x&&y); } | Sololearn: Learn to code for FREE!

+5

# Help me understand the output of this code #include <stdio.h> int main() { int x=2; int y=5; printf("%d",x&&y); }

+11

Boolean value of 0 is 0 which is equivalent to false. Anything else other than Zero is 1 which is equivalent to true. Here, you have x=2, so the boolean value of x is 1. The same for y=5. Then you used an and operator that works like this: True&&True =True. Or in other words: x&&y = 2&&5 = true = 1

+5

First of all && is a logical and operator if any of it is false(0) then result will be false(0) if two are true(1) then result will be true(1) Now ,u had given x=2 and y=5 There is no specific condition so we can say that above numbers are true 2&&5 = true&&true =true %d converts true into decimal So answer is 1

+4

It's Bit manipulation And :- && Or :- || Xor :- ^ Xnor :- ~^ Not :- ~ You have to remember all the truth tables and the boolean values like 2:- 0010 3:- 0011 4:- 0100 5:- 0101 like this and then compare each bits of the two of them and it will be a boolean operation. Example:- 2&&5 = (0010)&&(0100) = 0000 And is simply multiply. Or is simply add the bits. Not means compliment. Same as all further.

+2

Boolean value of 1=true Boolean value of 0=false

+2

In C, “&&” is Logical AND. Any number besides 0 (that is a non-zero number) is taken as true in logical expressions by the compiler. Thus, x && y => 2(non-zero)&&5(non-zero) => True&&True => True AND True => True. Thus, the expression will compute to TRUE. Decimal value of True is 1 and False is 0. So the output is 1

+2

x&&y=2&&5== non-zero value always true means that 1, then output become 1

+2

Anything other than 0 is considered as true.&& Is a logical operator which takes boolen values as operand and return a boolen value (0 or 1) as answer...if both the operands are true (not 0) the result is true (1) and in all other case it returns false (0) as result... Operand:the value on which operation is being performed Why 1 if true.? Ans: generally computer use 1 to represent true hope you got the answer 😀...

+1

x&&y => 2&&5 => true && true =>true Other than value 0, all treated as true as boolean equivalent. %d converts 1 so prints 1

+1

=0 means false and !=0 means true.. So true && true = true = 1 (for %d)

+1

The output is 1 because x=2 and y=5 are non-zero values. x&&y = 2&&5 which is true&&true so output is true and %d converts its to 1

0

Json Statham Adrenalin Rush попробуй эту комбинацию в html. https://code.sololearn.com/cuExE1R5i73o/?ref=app

0

It is nice (2) It is ok (1)

0

&& is a logical operator (AND). So your code is just saying 2 AND 5, without and condition and both values are true. So it will return you a True value as 1.

-2

Here boolean value of x&&y i.e. 2&&5 --> true&&true = true True = 1 False = 0 %d converts true into decimal ie. 1 So output of the code is 1