Microsoft Interview Question for Software Engineer / Developers






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

Actualy this program does not output anything. But if "what will happen" is asked, until the while block finds a null character the loop continues and dest will be set to null. Because Dest point to the +1 memory block of source this code will do lots of wrong memory changes.

- cac September 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is the case of exceeding the bounds of an array..
The program will crash at some point ...
because the null value in the input array has been overwritten by 'h' hence source will never find null and will never terminate.

- Yatharth September 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That's right

- cabbage September 25, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

good

- yes that's right October 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Since the source and destination pointers point to locations within the same array... the loop starts off with writing input[0] to input[1] and subsequently the dest and source pointers are kept at a distance of +1 apart from each other, the first character of the input character is written all over the array...now when the dest pointer is at null char of input[] the source pointer is at the character just before null char.. at this point the null char gets overwritten therefore the loop condition cannot terminate.. this program will probably crash as a result of segmentation fault or loop for an indefinite time.

- nana September 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

could you please explain in detail? I am not getting it. Thank you.

- nisarg September 26, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

nicely explain

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

Does the expression

while(*source != NULL)

involve a typo or is it a trick? Because it should be

while(source != NULL)

since there is no point in comparing if the "value pointed by a pointer" is NULL.

- erman September 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Seems to be typo.

- Response_erman September 30, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

H E L L O X X X X X X X X X X X X X X X X X X X X X X X X X
--------------------- M
Stack Overflow exception
or error in Memory access out of range

- Ankush Bindlish September 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Initial state
H E L L O X X X X X X X X X X X X X X X X X X X X X X X X X
|-----Array--------|------- Memory continues ----------

Intermediate state
H H H H H H H H H H H H H H H H H H H H H H H H ----------

Stack Overflow exception
or error in Memory access out of range
What exactly the exception would came out of this function execution ?

- Ankush Bindlish September 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Good analysis Yatharth...tricky but simple one..

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

dest pointer should be allocated memory before it is some character are added.
dest = new char[strlen(source)];

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

memory is already allocated. It is pointing to a[1]

- shanuapril December 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

tricky...didn't saw "NULL" at first

- raja August 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Actually, the loop "while" never ends, and eventually "dest" will point to garbage, "source" will point to letter"h" with garbage after.

- sergey.a.kabanov January 12, 2012 | 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