Yahoo Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

2nd/3rd options invalidate main's prototype.
IMO, the first one will compile because it is possible to cast * to int.

- Anonymous August 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thinking about it more, i think #2 will also work

- Anonymous August 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thinking about it more, i think #2 will also work

- Anonymous August 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Tried in code

with gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)..

and to my surprise, all worked though with a warning in 2 cases :(

- Anonymous August 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yes 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 August 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You have just compiled using gcc -c or its linked properly also ?

- Anonymous August 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@ 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

- Ashutosh September 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think it's compiler dependent feature. When compiler compiles, it doesn't know the exact prototype of main which will be called from startup routine [part of the loader domain I guess]

even u can see , main(a,b,c,d,e,f,g) - working and all the variables are stacked properly.

- anonymous November 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

compilerdoesnt really check for th prototype maybe, but it should give a runtime error. Did anyone check for runtime exception???

- go..on December 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- abhimanipal February 01, 2010 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More