The Gateway to Computer Science Excellence
+1 vote
int main()
    char boolean[][6]={"TRUE","FALSE"};
    printf("%s",boolean[(unsigned int)-1 == ~0]);
in Programming by Loyal (8.1k points) | 405 views

1 Answer

+3 votes
Best answer
See the logic here

char boolean[][6]={"TRUE","FALSE"};
printf("%s",boolean[(unsigned int)-1 == ~0]);
(unsigned int)-1// converting -1 to an equivalent unsigned integer value i.e 
the max value of unsigned int.
~0 // The bitwise complement operator ~ flips every bit .~0 means all 0 bits
are flips to 1 then here also we get same value as above i.e max value of unsigned int.

Finally (unsigned int)-1== ~0 becomes true and it displays.

First element of boolean array will be printed.


by Boss (38.7k points)
selected by
but %s means it will print all the character so why true will not be printed??? plz explain
all char of boolean[1] will be printed

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,357 answers
105,256 users