Solve it if u can... :P

0 views
Skip to first unread message

TheSuyog

unread,
Jul 31, 2010, 12:18:37 PM7/31/10
to Knowledge Test
Guys n Gals, I got a nice code for u to crack. Sure u can run it see
the o/p but u shud tell how it worked (if at all). So here goe the
code: (just the if-else block)

void main()
{
if(printf("%d", printf("123")), 0)
printf("Creepy code.");
else
printf("Crapy code.");
}

Best of luck!

Ravina

unread,
Aug 1, 2010, 5:40:41 AM8/1/10
to Knowledge Test

o/p=> 1233Crapy code

In if(printf("%d",printf("123")),0)

printf("123") print 123 and return no of char i.e 3
thus printf("%d",3) print 3 and return 1
now if (1,0) evaluate as false bcoz last element which
compiler found in if condition is 0
i.e false (if it is like if(2,0,3,0,1) last element 1 i.e
true)
and in last else printf print =>Crapy code

Hope it is clear to every one

Supriya Jain

unread,
Aug 4, 2010, 9:07:35 AM8/4/10
to knowledge-...@googlegroups.com
@ravina...great...:)

Ravina

unread,
Aug 4, 2010, 1:30:26 PM8/4/10
to Knowledge Test

thanx........
Reply all
Reply to author
Forward
0 new messages