HostGator Coupons

Saturday, February 20, 2010

ILLUSION:::C PROGRAM WITHOUT main()


Source code::::
#include<stdio.h>
#define decode(s,t,u,m,p,e,d)m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf("HELLO");
}
output:::::
HELLO


The TRICK::::::::
 Here we r using preprocessor directive #define with arguments to give  an impression that the program runs without main.But in reality it runs with a hidden main function
The ## is called token merging operator.So the logic is when u pass  (s,t,u,m,pe,d ) as arguments to decode(2nd line)  it merges the 4th ,1st,3rd and 2nd character which thus converts decode(a,n,i,m,a,t,e) into main which again replaces begin with main.
Hope u enjoyed it.


No comments:

Post a Comment

free counters