Here we have a c program which looks like it has no main function.
Can we write a C Program without the main function? the answer is No.
The main function is the entry point of your program, or in simple words from the main function your program starts execution.
But we can use the C PreProcessor and write a c program which looks like it doesn’t contain amain function.
Example C Program to mimic no main function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #include <stdio.h> /* create a macro which expands to main */ #define program main //create the function with macro name //this macro name will be substituted with macro expansion part // during the pre processing stage int program() { printf("Hello World"); return 0; } |
Output:
Hello World