fb7755ff1a01f69e42a95ffbf5f78b2034cae423aa17b209dd

Thursday, 4 August 2011

C PROGRAM WITHOUT MAIN( )

        Hi Friends! We all know to write a C program with main function.  How to write a C program without a main function?. Is it possible to do that. Yes there can be a C program without a main function. Here’s the code of the program without a main function…


#include<stdio.h>
#include<conio.h>
#define decode(h,a,r,i,s,z,e)## i##s##r##a
#define begin decode(a,n,i,m,a,t,e)
void begin()
{
printf(” hello “);

getch();
return 0;
}

         Does the above program run without the main function? Yes, the above program runs perfectly fine even without a main function. But how, whats the logic behind it? How can we have a C program working without main?

        Here we are 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 ‘##‘ operator is called the token pasting or token merging operator. That is we can merge two or more characters with it.

NOTE: A Preprocessor is program which processess the source code before compilation.



Look at the 2nd line of program -

#define decode(h,a,r,i,s,z,e) i##s##r##a


        What is the preprocessor doing here. The macro decode(h,a,r,i,s,z,e) is being expanded as “isra” (The ## operator merges i,s,r & a into isra). The logic is when you pass (h,a,r,i,s,z,e) as argument it merges the 4th,5th,3rd & the 2nd characters(tokens).


Now look at the third line of the program -

#define begin decode(a,n,i,m,a,t,e)



         Here the preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e). According to the macro definition in the previous line the argument must be expanded so that the 4th,5th,3rd & the 2nd characters must be merged. In the argument (a,n,i,m,a,t,e) 4th,5th,3rd & the 2nd characters are ‘m’,'a’,'i’ & ‘n’.

       So the third line “int begin” is replaced by “int main” by the preprocessor before the program is passed on for the compiler. That’s it…

      The bottom line is there can never exist a C program without a main function. Here we are just playing a gimmick that makes us beleive the program runs without main function, but actually there exists a hidden main function in the program. Here we are using the proprocessor directive to intelligently replace the word "begin" by “main”. In simple words int begin=int main.

      Thankyou friends for reading this.....

SOCIAL PLUGINS TO YOUR WEBPAGE :

    Hi friends! I am Harish.  I hope you all have seen Social Plugin in almost all the webpages.  Have you ever thought of adding those plugins in your web page? If you do,then here is a way to add social plugin like Facebook Like button, Google Plus button, Twitter Tweet button, Facebook login button etc, to your webpage.

     Friend here is the link to add facebook like button to your webpage.  click on the below link to go to the facebook developers page.

http://developers.facebook.com/docs/reference/plugins/like/

       There you will see a form like something which will ask you for your URL link. After providing your link and some other attributes , Press GET CODE.  Now the code will be generated and you can copy the code and paste it in your webpage source wherever you want.  Similarly, you can also add google plus button to your webpage by just pasting the following code in your webpage.

        This is the code that goes into the header:
<script type="text/javascript" src="http://apis.google.com/js/plusone.js"></script>

        This is the code that you insert where you want the +1 button to appear:
<g:plusone size="tall"></g:plusone> 
                 
     For adding tweet button to your webpage, here is the code.
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>


      Guys you can also add facebook comments button to your webpage. To do so click the link which will redirect you to Facebook Developer page.  Procedure for getting the code is similar to that of Facebook Like button.
  FACEBOOK COMMENTS

      For more information , please comment on this.Thankyou friends.