Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
5
of 7 vote

In the first one an int is casted into (int*) and then it is dereferenced, hence if i was equal to 10(suppose), you are dereferencing variable at address 10, this could be a segmentation fault.

The second one is fine in that p will have the value of i.

- Luv June 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Absolutely correct.

- aThakur June 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

What is i here? Not clear form the question. If i is an int. Answer is perfect. Think what if i is a int* ?

- Observer June 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I like the soln but Observer's point seems valid. This needs to be revisited by Luv.

- Dilbert Einstein July 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Actually Observer is perfectly saying correct.
if variable i is a pointer to float(suppose), then first line is correct and second one is incoorect.
So, it completely depends upon the nature of variable i.

- Amit Priyadarshi June 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Interesting point.

- eugene.yarovoi June 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

may be i is a void *

- Aalok June 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Amit Priyadarshi : i did not get you, plz explain briefly.... ???

- Raj Naik June 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The first answer given by Luv is correct

- Raj June 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is segmentation fault??

- kishore June 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

In his case, 10 would definitely [ Ok most probably ] be a memory location that is allotted for the OS related basic operation..service routines etc. So, code trying to access them would fail.

- Pavan Dittakavi June 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

To be more specific, code trying to access those memory locations would receive a signal from the operating system that it's not permitted to access them. The program will then typically terminate.

- eugene.yarovoi June 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming that both statements are currect, then in the 1st one i is a pointer which can be casted to int *. In the second one i is an integer (or any variable whose address can be casted to int *.

- IntwPrep December 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming that both statements are correct, then in the 1st one i is a pointer which can be casted to int *. In the second one i is an integer (or any variable whose address can be casted to int *.

- IntwPrep December 04, 2013 | 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