Microsoft Interview Question for Software Engineer in Tests


Country: India




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

I think a good answer is sizeof (int*) + sizeof (char*), provided those declarations are not optimized away.

- eugene.yarovoi October 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even n * sizeof(int) should work

- Arxo Clay October 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@aniket: What's n? There's no n anywhere in this problem. If you allocated an array of some size n through malloc and assigned the address of the start of this array to one of these pointers, the memory for the array would be on the heap and not on the stack, and it would still be the case that only the pointer would be on the stack. The answer as to the amount of on-stack memory used would still be what I said.

- eugene.yarovoi October 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

is it correct to say that sizeof (int*) = 32 bits
and sizeof (char*)= 32 bits so 8 bytes? or am i making a certain assumption?

- sabio October 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

is it correct to say that sizeof (int*) = 32 bits
and sizeof (char*)= 32 bits so 8 bytes? or am i making a certain assumption?

- sabio October 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, you're making an assumption. The size of pointers is machine-dependent and may be 8 bytes on a 64-bit system. The truly portable way to get the size is by using the sizeof operator.

- eugene.yarovoi October 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

On a n bit machine, it will be as many bytes as the n bit address corresponds to. For example, on 32 bit machine, both will have 32 bit address and hence need 4 bytes each.

- AmzFAILFacebookFailMSFTFail January 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

two pointers (in a 64bit computer, it should be 8 bytes x 2 = 16 bytes ?)

- biostanley October 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It could also be zero if the optimizer decides to optimize it away.

It could be greater than 8 bytes if some ASLR stuff happens

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

um guys.... Pointers don't take memory from stack right? O.o They take it from heap. Shouldn't answer be 0?

- shanuapril November 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, AFAIK they act like any other variable.
For instance, if you declare a pointer in main, it will take memory from stack. Global pointers will take it from heap.

- phantom November 10, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In ILP32 systems(32 bit machine), size of pointer is 4 bytes, so it takes 4+4= 8 bytes and on ILP64 (64 bit machine), size of pointer is 8 bytes, so it takes 16 bytes. Pointer size doesn't depend on the type of the variable, the memory location where it points depends on the type.

- pbingi March 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 4 vote

IT WILL TAKE THE MEMORY OF TWO INTEGERS.
if its of 4 bytes than 8 bytes for two pointers.

- Anonymous October 20, 2011 | 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