How to write a running code without main() ?

There are two ways to solve this question.
1. By using Macros :-
A macro is an identifier defined in a #define preprocessor directive.As with symbolic constants,the macro-identifier is replaced in the program with the replacement-text before the program is compiled.
Sol:-

#include<conio.h>
#include<iostream>
using namespace std;
#define fun main

 

int fun()
{
cout<<"Code is running without main().";
getch();
return 0;
}

Output :-

Code  is running without main().

2. By using Token-Pasting Operator :-
The ## operator concatenates two tokens.The ## operator must have two operands. ## called Token-Pasting operator.

#include<iostream>
using namespace std;
#define fun m##ai##n

int fun()
{
cout<<"Code running without main().";
return 0;
}

Output :-

Code  is running without main().

 

Leave a comment