C Program to Write
C Program Without
using Main Function
in 3 ways
Run C Program Without Main Function
Conceptually C Program is meaningless without main Function . Every
Program Must have Main Function.
Main Function :
a] It is Entry Point of Every C Program.
b] All Predefined and User-defined Functions are called directly or
indirectly through the main.
c] So C Program Must have Main Function.
But I have decided not to write main and want to run C Program , How ?
We have 3 approaches of Writing C Program without using main().
1
2
3
4
5
6
7
#include<stdio.h>
#define begin main
int begin() {
printf("Hello");
return (0);
}
Way 1 : Using #define Preprocessor Directive
Way 1 : Using #define Preprocessor Directive
What Preprocessor is doing Here ?
• Save C Program using Extension .C
• Before Program is given to compiler program is processed by
Preprocessor .
• 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”
1
2
3
4
5
6
#include<stdio.h>
#define begin m##a##i##n
void begin() {
printf("Hello");
}
Way 2 : Using #define Token Merging Operator
Explain ?
• The ‘##‘ operator is called the token pasting or token merging operator.
• That is we can merge two or more characters with it.
1
2
3
4
5
6
#include<stdio.h>
#define begin m##a##i##n
void begin() {
printf("Hello");
}
Way 3 : Using Argumented Macro

C program to write c program without using main function

  • 1.
    C Program toWrite C Program Without using Main Function in 3 ways
  • 2.
    Run C ProgramWithout Main Function Conceptually C Program is meaningless without main Function . Every Program Must have Main Function. Main Function : a] It is Entry Point of Every C Program. b] All Predefined and User-defined Functions are called directly or indirectly through the main. c] So C Program Must have Main Function. But I have decided not to write main and want to run C Program , How ? We have 3 approaches of Writing C Program without using main().
  • 3.
    1 2 3 4 5 6 7 #include<stdio.h> #define begin main intbegin() { printf("Hello"); return (0); } Way 1 : Using #define Preprocessor Directive
  • 4.
    Way 1 :Using #define Preprocessor Directive What Preprocessor is doing Here ? • Save C Program using Extension .C • Before Program is given to compiler program is processed by Preprocessor . • 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”
  • 5.
    1 2 3 4 5 6 #include<stdio.h> #define begin m##a##i##n voidbegin() { printf("Hello"); } Way 2 : Using #define Token Merging Operator Explain ? • The ‘##‘ operator is called the token pasting or token merging operator. • That is we can merge two or more characters with it.
  • 6.
    1 2 3 4 5 6 #include<stdio.h> #define begin m##a##i##n voidbegin() { printf("Hello"); } Way 3 : Using Argumented Macro