Run C Program Without Main Function
Conceptually C Program is meaningless without main Function . Every Program Must have Main Function.
Main Function :
But I have decided not to write main and want to run C Program , How ?
- It is Entry Point of Every C Program.
- All Predefined and User-defined Functions are called directly or indirectly through the main.
- So C Program Must have Main Function.
We have 3 approaches of Writing C Program without using main().
Way 1 : Using #define Preprocessor Directive
What Preprocessor is doing Here ?#include<stdio.h> #define begin main void begin() { printf("Hello"); }
- Save C Program using Extension .C
- Before Program is given to compiler program is processed by Preprocessor .
#define begin main
- Source Program is scanned from Left to Right and from Top to Bottom and "begin" is replaced by "main"
- So Programmer feels that "He has written Code Without using Main , but internally begin is already converted into main"
Way 2 : Using #define Token Merging Operator
Explain ?#include<stdio.h> #define begin m##a##i##n void begin() { printf("Hello"); }
Way 3 : Using Argumented Macro
- The ‘##‘ operator is called the token pasting or token merging operator.
- That is we can merge two or more characters with it.
Explain ?#include<stdio.h> #define begin(m,a,i,n) m##a##i##n #define start begin(m,a,i,n) void start() { printf("Hello"); }
- See Argumented Macro

0 comments
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email