Miscellaneous › Others › C program without writting main() function
- This topic has 3 replies, 2 voices, and was last updated 12 years, 1 month ago by
AJISH ALFRED.
-
AuthorPosts
-
February 24, 2013 at 5:49 am #2131
Monika
ParticipantHi….
Can anyone plzzzzz make me understand how the code works of a program without a main() function.
I am writting a program below, it works correctly and gives the desired output but I am unable to understand its logic. Plzzzzz help me here to get the concept. And one more thing, as I am a BCA pursuing student so which forum should I join???
#include<stdio.h>
#define decode(s,o,l,v,i,n,g)v##s##l##o
#define start decode(a,n,i,m,a,l,s)
void start()
{
printf(“Hello”);
}
February 24, 2013 at 10:05 pm #9177AJISH ALFRED
ParticipantHi Monika,
Interesting question.
There is actually a main() there in your code.
Try to understand the meaning of the following macros.
#define decode(s,o,l,v,i,n,g)v##s##l##o
A function named ‘decode’ with 1st argument ‘s’, second argument ‘o’, third argument ‘l’ and so on, is defined as nothing but a ‘string’, formed by concatinating the following arguments in the order,
v – 4th argument
s – 1st argument
l – 3rd argument
0 – 2nd argumnet
Now this function is called by another function named ‘start’ which is defined as below.
#define start decode(a,n,i,m,a,l,s)
A function named ‘start’ with no arguments, is defined as making a fucntion call to the already defined function ‘decode’ along with passing value to 1st argument as ‘a’, 2nd argument as ‘n’ and so on.
Now the working! On this function call the function ‘decode’ receives the argument values as follows
No. argument value received
1 s a
2 o n
3 l i
4 v m
5 i a
6 n l
7 g s
Now what the ‘decode’ function is defined as?
It forms a string by concatinating the values of arguments in the order v, s, l, o
argument value concatenation process
v m m
s a ma
l i mai
o n main
You see how the main is made??
Simply, the function ‘start’ is defined as making a function call to decode which is alredy defined as generating a string ‘main’ on that function call from start.
Hence ‘start’ is indeirectly defined as ‘main’
It is like writing the following statement
#define start main
I hope this ‘animal’ has helped you in ‘solving’ your question much better than people from other forums do!!
You can concentrate on forums based on programming questions only. Since your questions will be answered by people who have spend major part of their life in programming, they will consider these kind of questions as silly once and you won’t get an explanation like the one I’ve given you on your question.
So I suggest you to try the people on other general technical forums like engineers garage’s before bothering experts on programming questions based forums.
February 25, 2013 at 2:44 pm #9183Monika
ParticipantHi Ajish…
Thank you so much for the explanation.
February 26, 2013 at 1:37 pm #9186AJISH ALFRED
ParticipantYou are welcome.
-
AuthorPosts
- You must be logged in to reply to this topic.