Friday, June 3, 2011
Here is a C puzzle I like to ask my friends and colleagues. It is one of those silly puzzles that may bring a smile on your face if you aren't able to figure it out immediately.
#include <stdio.h>
int main()
{
http://blog.susam.in/2011/06/urls-in-c.html
printf("URLs in C\n");
return 0;
}
This code compiles and runs successfully even though the C99 standard doesn't mention anywhere that URLs are valid syntactic elements in C. How does this code work then?



9 comments:
kunkunur said:
is it like this?
http: is considered as label and the rest is considered as comment?
Mandeep said:
http: makes it a label...and the rest is a comment! :P
nice one.
abhay said:
smart hack. both kunkunar and Mandeep are correct.
Iouri said:
url.c: In function ‘main’: url.c:5: warning: label ‘http’ defined but not used
Yuvi Panda said:
Nice one! And yay, I got it under a 10 seconds too :D :D
Anuvrat said:
comment was obvious but labels were not. awesome!!!
krace-the kingmaker said:
Nice question ,checks depth of understanding in C.
Vikas Burte said:
Simple yet cryptic! Basics!
Pratik Agrawal said:
good one