C Program Without a 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…

#define HRS(f,a,c,e,b,o,Q,k) f##b##Q##k
#define shadhin HRS(m,r,s,h,a,d,i,n)

//HRS = Habibur Rahman Shadhin

int shadhin()
        printf(“”Shadhin” Awesome!!!!!!!!!!!!!!”);

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 processes the source code before compilation.

Look at the 2nd line of program –

#define HRS(f,a,c,e,b,o,Q,k) f##b##Q##k

What is the preprocessor doing here. The macro HRS(f,a,c,e,b,o,Q,k) is being expanded as “fbQk” (The ## operator merges f,b,Q&k into fbQk). The logic is when you pass (f,a,c,e,b,o,Q,k)as argument it merges the 1st,5th,7th& the 8th characters(tokens).

Now look at the third line of the program –

#define shadhin HRS(m,r,s,h,a,d,i,n)

Here the preprocessor replaces the macro “begin” with the expansion HRS(m,r,s,h,a,d,i,n). According to the macro definition in the previous line the argument must be expanded so that the 1st,5th,7th& the 8th characters must be merged. In the argument (m,r,s,h,a,d,i,n)  1st,5th,7th& the 8th characters are ‘m’,’a’,’i’ & ‘n’.

So the third line “int shadhin” 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 shadin=int main.


Language: C++

#include <stdlib.h>
void welcome(void);
void thanks(void);
using namespace std;
int main()
char file;
char s;
printf(“Are you sure to run this? Y/Nn”);

ifstream shadhin(“links.txt”);
char link[5000];
if(file==’y’ || file==’Y’)
cout<<“nn”links.txt” file missing.!!! First close the progarm then Put the file and run again.n”;
cout<<“Press CTRL+Z then Enter to exit.”<<endl;
return 0;
cout<<“nProgram is now runnig…………………..”<<endl;
ShellExecute(NULL, “open”, link,
cout<<“nWork is done.”;
}else if(file==’n’ || file==’N’){
cout<<“nThank you! Best of luck for next time.n”<<endl;
cout<<“Oops!!!!!! You enter invalid key.Run again and give right key.”<<endl;
cout<<“Press CTRL+Z then Enter to exit.”<<endl;

return 0;

void welcome(void)
cout<<“Welcome!This is an auto urls opener program that Developed by H.R.Shadhin”<<endl;
void thanks(void)
cout<<“Thank you for using this program.”<<endl;
cout<<“Give feedbacks on: hrshadhin.wordpress.com”<<endl;
cout<<“E-mail:dev[AT]hrshadhin[DOT]me “<<endl;

Programming Languages are Like Women

 There are so many programming languages available that it can be 
very  difficult to get to know them all well enough to pick the 
right one for you.  On the other hand most men know what kind of 
woman appeals to them. So here  is a handy guide for many of the 
popular programming languages that describes  what kind of women 
they would be if programming languages were women.

 Assembler - 
A female track star who holds all the world speed 
records.  She  is hard and bumpy, and so is not that pleasant to 
embrace.  She can cook up  any meal, but needs a complete and 
detailed recipe.  She is not beautiful or  educated, and speaks in 
monosyllables like "MOV, JUMP, INC".  She has a  fierce and 
violent temper that make her the choice of last resort.

Your grey-haired grandmother.  People make fun of her 
just because  she is old, but if you take the time to listen, you 
can learn from her  experiences and her mistakes.  During her 
lifetime she has acquired many  useful skills in sewing and 
cooking (subroutine libraries) That no younger  women can match, 
so be thankful she is still around.  She has a notoriously  bad 
temper and when angered will start yelling and throwing dishes.  
It was  mostly her bad temper that made grandad search for another 

A plump secretary.  She talks far too much, and most of 
what she says  can be ignored.  She works hard and long hours, but 
can't handle really  complicated jobs.  She has a short and 
unpredictable temper, so no one really  likes working with her.  
She can cook meals for a huge family, but only knows  bland 

The horny divorcee that lives next door.  Her specialty 
is seducing  young boys and it seems she is always readily 
available for them.  She  teaches them many amazing things, or at 
least they seem amazing because it is  their first experience.  
She is not that young herself, but because she was  their first 
lover the boys always remember her fondly.  Her cooking and  
sewing skills are mediocre, but largely irrelevant, it's the 
frolicking that  the boys like.  The opinion that adults have of 
Mrs.  BASIC is varied.  Shockingly, some fathers actually 
introduce their own sons to this immoral  woman!  But generally 
the more righteous adults try to correct the badly  influenced 
young men by introducing them to well behaved women like Miss  

 PL/I - 
A bordello madam.  She wears silk dresses, diamonds, furs 
and red high  heels.  At one time she seemed very attractive, but 
now she just seems  overweight and tacky.  Tastes change.

 C - 
A lady executive.  An avid jogger, very healthy, and not too 
talkative.  Is an good cook if you like spicy food.  Unless you 
double check everything  you say (through LINT) you can unleash 
her fierce temper.  Her daughter C++  is still quite young and 
prone to tantrums, but it seems that she will grow  up into a fine 
young woman of milder temper and more sophisticated character.

 ALGOL 60 - 
Your father's wartime sweetheart, petite, well 
proportioned, and  sweet tempered.  She disappeared mysteriously 
during the war, but your dad  still talks about her shapely form 
and their steamy romance.  He never  actually tasted much of her 

 Pascal - 
A grammar school teacher, and Algol 60's younger sister.  
Like her  sister she is petite and attractive, but very bossy.  
She is a good cook but  only if the recipe requires no more than 
one pot (module).

 Modula II 
- A high-school teacher and Pascal's daughter.  Very 
much like her  mother, but she has learned to cook with more than 
one pot.

 ALGOL 68 - 
Algol 60's niece.  A high-society woman, well educated 
and terse.  Few men can fully understand her when she talks, and 
her former lovers still  discuss her mysterious personality.  She 
is very choosy about her romances  and won't take just any man as 
her lover.  She hasn't been seen lately, and  rumor has it that 
she died in a fall from an ivory tower.

 She is an aging beatnik, who lives in a rural commune with 
her hippie  cousins SMALLTALK and FORTH.  Many men (mostly college 
students) who have visited the farmhouse,-- enthusiastically 
praise the natural food, and perpetual love-ins that take place 
there.  Others criticize the long cooking times, and the abnormal 
sexual postures (prefix and postfix). Although these women seldom 
have full-time jobs, when they do work, their employers praise 
them for their imagination, but usually not for their efficiency. 

APL - 
A fancy caterer specializing in Greek food.  She can cook 
delicious meals for rows and rows of tables with dozens of people 
at each table.  She doesn't talk much, as that would just slow her 
work down.  Few people can understand her recipes, since they are 
in a foreign language, and are all recorded in mirror writing.

LOGO - A grade-school art teacher.  She is just the kind of 
teacher that you wish you had when you were young.  She is shapely 
and patient, but not an interesting conversationalist.  She can 
cook up delicious kiddie snacks, but not full-course meals.

These clever teenagers show a new kind of cooking 
skill. They can cook-up fine meals without the use of recipes, 
working solely from a description of the desired meal (declarative 
cooking).  Many men are fascinated by this and have already 
proposed marriage.  Others complain that the girls work very 
slowly, and that often the description of the meal must be just as 
long as a recipe would be.  It is hard to predict what these girls 
will be like when they are fully mature.

Ada - 
A WAC colonel built like an amazon.  She is always setting 
strict rules, but if you follow them, she keeps her temper.  She 
is quite talkative, always spouting army regulations, and using 
obscure military talk.  You gotta love her though, because the 
army says so.