Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
4
of 6 vote

Tried compiling with Dev c++ (Which internally uses gcc for c files)
- Nothing is printed when for(;0;)
- Infinite loop when for(;1;)

- snk_anindya February 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is that an Amazon question indeed ?

- AV October 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

body of cycle will not run a single time because condition for cycle working/entering it is constantly false (0 - false).

And that was asked by Amazon`s interviwer?

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

test for attention must be something like that

for(;0;);
printf("\n guess");

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

Amazon didn't ask this, come on..

- Anonymous October 31, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i think so too.

- daksh December 06, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

guys cn u guide me abt d written pattern and ques for amazon..
at careercup i cn find a lot of interview questions..bt wat abt d written??

- help needed November 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

nothing will print because if we don't mention any condition then default condition is true but in 0 indicates false so control doesn't enter into loop

- kondu naresh November 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The legendary Dennis Ritchie clearly explains for loop (for (init; cond; inc/dec)) is nothing but a while loop with the following structure:

init;
while (cond)
{
// body
inc/dec;
}

Hence, the condition (0) fails and the body is never executed.

- Vikas Upendra November 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@all above

answer comes and it prints guess

- sandy880 January 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, it shows 'No errors or program output.'

- pavithra January 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

actually no, you are wrong. nothing will get executed but the program will run successfully.

- daksh December 06, 2021 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

yes, it prints guess

- Anonymous January 31, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

I have tried other options too :
->if 0 is replaced by any other no.(i.e. true) then, it prints guess infinite number of times,
->if 0 is replaced by FALSE(defined as 0), then it also prints guess just once
CONSIDERING THESE CASES IT SEEMS THAT :- "for loop without any initialization and incre/decre, it works as do-while loop"
!!!BUT again contrary to this when 0 is replaced by any wrong condition it behaves like while loop(i.e. don't print guess, as expected)
PLEASE SOMEONE HELP WITH SOME EXPLANATION

- Anonymous February 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Its because..a for loop will always do the initialisation first and executes the loop's body...ONLY after executing the loops body once,it will check for the condition..

So..in this case ...it executes loop's body once..then it finds 0(ie .false) ,hence it quits but instead of 0,any other number is considered true,hence executes infinite number of times...

- sha February 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

if for loop follows do-while loop, then it should execute the loop body at least once as for the earlier case even if, 0 is replaced by some wrong condition(like int i=0;
for(;i<0;) printf("\nGUESS");
BUT ITS CONTRADICTORY TO THE ASSUMED CONCLUSION AND DOES NOT PRINT ANYTHING

- Anonymous February 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@sha
you are wrong ,during 1 st iteration it is initialized and condition is checked before executing the body

try this code
for(x=1;x>2;x++)
printf("%d",x);

so according to you it should have printed 1 ,but it won't print because condition is also checked before entering body

- Sandy880 February 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yeah that's true for( ;0; ) runs the body for one time and even for(int i=0;0; ) runs the body once, but for(int i=0;i<0; ) the body does not gets executed for a single time.
I don't know the reason. If anybody does, please help.

- kriti13796 September 20, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

for(;0;)
    printf("\n guess");

#nothing is printed because it is false.

- weijiang2009 February 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

actually its printing guess once beyond all logical reasoning

- Anonymous February 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

(1)do the initilization, print once.
(2)and then judge, do nothing and exit

- weijiang2009 February 06, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

nothing would print. because before going printf statement thew would exit.due to for(;0;)

- Anonymous April 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(;0;)
printf("\n guess");


Output:
No errors or program output.

and please dont joke this cant be amazom question

- Learn Android: http://learnandroideasily.blogspot.in/ June 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Nothing will be printed.....

- Sanchit Choubey November 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sha is correct

- Anonymous February 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(;;;)

- Anonymous May 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the logic of 0 is to tell the compiler that you have interacted or tested a false condition, thus the output comes out to be [null] or ASCII decimal value '0'.

- daksh December 06, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it is also of the same form as for(; ;) where the empty space represents [null] which in arithmetic conditions will take up its ascii decimal value of 0, hence nothing will get executed and the program will exit out with the return code.

- daksh December 06, 2021 | 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