#include<iostream.h>
#include<conio.h>
#define begin
decode(a,n,i,m,a,t,e)
void begin()
{
cout<<"Hello
This is wihtout main";
getch();
}
EXPLANATION
1.
#include<iostream.h>
#include<conio.h>
In
first step we include two standard
library files “ #include<conio.h>
“ for getch() and “#include<iostream.h>”
for cout
2.
#define
decode(s,t,u,m,p,e,d) m##s##u##t
This is Macro . Macros are generally a small
block of code that is replaced everywhere in program where Macro name occurs it
will replace that macro name with small code provided with macro name at time
of macro declaration.
In this decode is Macro name . and it is given
parameters :- s,t,u,m,p,e,d.
All logic is in code given after macro
name that is :- m##s##u##t
Now I will numbered the parameter given to
macro to understand you how it actually act as main:- s t u m p e d
1
2 3
4 5 6 7
S
t u m p e d
Now
value given to replace occurrence of macro is :- m##s##u##t .Now numbered it according to numbers given
to parameters ..
Example:-
s =1
t=2
u=3
m=4
p=5
e=6
d=7
m
## s ##
u ## t
4 1 3 2
Step 3. :- line 3 in
program
#define begin
decode(a,n,i,m,a,t,e)
Now we have done decode macro
function in step 2. In this step begin macro will be replaced by numbered order
of decode . In this parameters given to decode is different is different as
compared to decode arguments in previous step But It uses the code of 4,1,3,2 as same .
## is a Token Merging Operator .
That will get out 4th , 1st
,3rd ,2nd letter from arguments of decode and then
combine them or merg them as we are using
Token Merging Operator.
4th letter
= m
1st letter
= a
3rd
letter = i
2nd letter = n
So according to third
statement macro begin will be replaced with main for each occurrence in
program. So actually if we see logically then we are using Main program but it
is a of hiding it from user.
0 Comment to " Cplusplus program without Main Function"
Post a Comment