Yahoo Interview Question
Software Engineer / Developersyes Anonymous, all 3 are working. But Why? I am not geeting any clue why it is working.
Initially before executing I thought, 1st one will compile through but 2nd and 3rd will not. my reason was that, in 1st case we are not overloading main, so it will compile. But rest of the cases we are trying to oveload main function. So I though it wll not compile. But all 3 get compile through. Don't kw why? anyboby can explain?
@ Anonymous
I think, its moreover compiler dependent stuff.
But as per language point of view, the main function should have the below properties
1: first argument of 'main' should be `int'
2: second argument of 'main' should be 'char **'
3: return type of 'main' should be int
Please try the test item with gcc's -Wall option
$gcc test.c -Wall
I wrote a printf statement in the main and the code thrice... Each time with different definition of main. Each time I got the same error
timberlake {~} > gcc test.c -o test
test.c: In function âmainâ:
test.c:7: warning: return type of âmainâ is not âintâ
Then when I ran the code to see if there was any run time bug, to my surprise there was none
2nd/3rd options invalidate main's prototype.
- Anonymous August 31, 2009IMO, the first one will compile because it is possible to cast * to int.