+ 5

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

13th May 2021, 7:36 PM
Navin kumar
Navin kumar - avatar
15 ответов
+ 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
13th May 2021, 9:02 PM
Hisham YUM 🇲🇦
Hisham YUM 🇲🇦 - avatar
+ 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
15th May 2021, 3:32 AM
Kolla Vinod
Kolla Vinod - avatar
+ 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.
14th May 2021, 2:18 PM
Vishal Pandey
+ 2
Boolean value of 1=true Boolean value of 0=false
13th May 2021, 8:42 PM
Atul [Inactive]
+ 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
15th May 2021, 7:01 AM
GAYATHRI KOLLURI
GAYATHRI KOLLURI - avatar
+ 2
x&&y=2&&5== non-zero value always true means that 1, then output become 1
15th May 2021, 9:20 AM
Vrushabh
Vrushabh - avatar
+ 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 😀...
15th May 2021, 1:15 PM
MOHD AIMAN SALEEM
MOHD AIMAN SALEEM - avatar
+ 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
13th May 2021, 8:15 PM
Jayakrishna 🇮🇳
+ 1
=0 means false and !=0 means true.. So true && true = true = 1 (for %d)
15th May 2021, 6:38 AM
Anup Panchal
Anup Panchal - avatar
+ 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
15th May 2021, 2:48 PM
Vishwajeet Gaikwad
Vishwajeet Gaikwad - avatar
0
boolean
15th May 2021, 10:03 AM
Rossukhon Rukkiattikhun
Rossukhon Rukkiattikhun - avatar
0
Json Statham Adrenalin Rush попробуй эту комбинацию в html. https://code.sololearn.com/cuExE1R5i73o/?ref=app
15th May 2021, 3:40 PM
Александр Ялухин
Александр Ялухин - avatar
0
It is nice (2) It is ok (1)
15th May 2021, 4:14 PM
shaik unnis
shaik unnis - avatar
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.
15th May 2021, 6:38 PM
Pankaj Rawat
Pankaj Rawat - avatar
- 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
14th May 2021, 10:17 AM
Rohit Yadav
Rohit Yadav - avatar