Tuesday 5 March 2013

c programm without main function


Just type the following code in your C editor. (For example Turbo C/C++):


  • #include
  • #include
  • #define decode(s,t,u,m,p,e,d) m##s##u##t
  • #define kgtricks decode(a,n,i,m,a,t,e)
  • int kgtricks()
  • {
  • clrscr();
  • printf(" C Program Without Main function");
  • getch();
  • return 0;
  • }
C Program input Source Code


  • OUTPUT:
  • C Program Without Main function
Output of C Program Without Main Function


Now most of you still may be wondering about the fact that how come the above program run without Main Function.

The secret is that the preprocessor directory #define line of code combined with decode work together to form a hidden Main function.


The '##' operator is known as the token pasting or token merging operator. We can merge two or more characters using it.

Preprocessor : A program which process source code before compilation.


In the Line '#define decode(s,t,u,m,p,e,d)m##s##u##t
 The macro decode(s,t,u,m,p,e,d) is expanded as "msut".
The ## operator merger m,s,u & t into msut.


No comments:

Post a Comment