C Program without main() function - Programming Puzzles

We can write c program without using main() function. To do so, we need to use #define preprocessor directive.

The C preprocessor is a micro processor that is used by compiler to transform your code before compilation. It is called micro preprocessor because it allows us to add macros.

A macro is a segment of code which is replaced by the value of macro. Macro is defined by #define directive.

For example:

#define PI 3.14

Here, PI is the macro name which will be replaced by the value 3.14.

Let's see a simple program to print "Hello, World!!!" without main() function.

#include<stdio.h>  
#define start main  
void start() 
{  
   printf("Hello, World!!!");  
}  

Output:

Hello, World!!!

Discussion

Read Community Guidelines
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.