Dec 12, 2009

WRITE A C PROG WITHOUT main() FUNCTION

C program (code) without using main() function:

HAVE U EVER IMAGINED TO WRITE A C PROG WITHOUT MAIN FUNCTION ??

I just thought to share this example. Actually, its not really a example without main() function. Rather its a preprocessor directives trick in order to write c program without the line int main(). Or simply to say, it allows us to write C programs without using the main() function.
The code is:

#include
#include


#define kavi main

int kavi(int argc, char *argv[])
{
printf("kavi is Here!");
getch();
return 0;
}



Here I have defined a macro kavi as main so kavi would be replaced by main thus actually making it int main().

Now I would like to show you small modification in it.

#include
#include


#define trickit(k,a,v,i,e,p) k##a##v##i
#define kavi trickit(m,a,i,n,e,p)

int kavi(int argc, char *argv[])
{
printf("kavi is Here!");
getch();
return 0;
}


This code is also actually same as the previous code but I have obscured it a little. You may try it on your own.
I hope this was useful.

COMMENTS :

Don't Spam Here

0 comments to “WRITE A C PROG WITHOUT main() FUNCTION”

 

Copyright © 2009 UTOPIAN WORLD | Designed By NdyTeeN | Magazine Template. All Rights Reserved. Powered by Blogger and Distributed by Blogtemplate4u .