Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
18
of 22 vote

Actually it is not a RULE that a stack will always grow downwards and the heap will always grow upwards. It depends on the OS that you are using. But ya in most of the modern systems stack generally grows downwards and heap grows upwards.
In the modern system there is actually no chance of collision. If the stack is full and it tries to enter into the heap area then you will get a stack overflow error. On the other hand if heap is full then the call to "malloc()" will return null. Now it depends on the programmer to check whether malloc() returned null or not.

Hope I am clear.. :)

- Spock July 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Initially both segments are allocated with some fixed amount of memory, when either of it gets overflown, The information is signaled to the OS, where it extends the overflow limit. when it is extending, it might check for the overlapping condition.

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

There will be break pointer which marks the end of the heap area. When it requires more memory space it will be extended by using system call such as brk()

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

kannathal: Sure there is a break pointer but that signals the end of current heap(not necessary that the heap is maxed out, it just shows the current status of heap). when brk is called by malloc the break pointer is moved ahead by the amount of heap required.

- Rishabh Pandita October 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is no hard-n-fast rule of stack grows downwards and heap upwards...it depends on operating systems , and the way they handles the memory if the operating system is present in lower memory area then stack generally grows downwards and heap upwards. And For collision how a complier can decide that stack is going to collide with heap so this thing happens dynamically. Hope you remember the concept of segments on x86 architecture , there are segments like stack segment , so segments will no allow you a stack to go inside the heap area.

- m2anuj December 22, 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