Bloomberg LP Interview Question for Software Engineer / Developers






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

call a function with variable recursively. that shoudl solve it.

normally its always a stack which grows down , heap grows up,

may be that is why we have stack underflow and buffer overflow :)

- ani August 26, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't get the idea behind this question.
Declaring two local variables and comparing their address would be enough wouldn't it?
If the first variable has greater address value, then the stack grows upward, otherwide downward...

- recentKid March 11, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think that would work. I think the purpose of this question is to see if you know about stack frames.

- Khoa March 13, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

yeah...its just that you know that there exists smthing called system stack

- ska March 13, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Couldn't the compiler arbitrarily reorder the order of local variables on the stack frame?

I'd think the way to do this would be:

#include <stdio.h>
void g(int* pi)
{
  int j;
  printf("g(): address of j: %p\n", &j);
  if (&j > pi)
    {
      printf("stack grows up\n");
    }
  else
    {
      printf("stack grows down\n");
    }
}

void f()
{
  int i;
  printf("f(): address of i: %p\n", &i);
  g(&i);
}

void f1()
{
  int i;
  int j;
  printf("f1(): address of i: %p\n", &i);
  printf("f1(): address of j: %p\n", &j);
  if (&j > &i)
    {
      printf("stack grows up\n");
    }
  else
    {
      printf("stack grows down\n");
    }
}

int main(char** pszArgs, int cArgs)
{
  f();
  f1();
}

With gcc, both result in "stack grows down".

I think the order of local variables on the stack (f1 from the code above) is implementation dependent. Correct me if I'm wrong.

At the very least my solution will work because we're adding a stack frame. Without some kind of fancy whole program optimization it should give the correct answer.

- cracc August 18, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* To show if the stack is increasing or decreasing */
#include<stdio.h>
void f1();
void f2();
void f3();
void main()
{
int a =1;
printf("The address of a is %d \n", &a);
f1();
int c = 5;
printf("The address after f1 and f2 has finished is %d \n", &c);
}
void f1()
{
int b= 2;
printf("The address of b is %d \n", &b);
f2();
}
void f2()
{
int c = 3;
printf("The address of c is %d \n", &c);
}

- gauravk.18 December 08, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a, b;
cout << (&b - &a > 0 ? "increasing" : "decreasing");

- snowden February 22, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

WHY THE F_CK YOU THEY CARE IF THE STACK GROW UP OR DOWN.. DOES IT HAVE AN EFFECT ON THE FUNCTION.. IF NOT. THIS IS A STUPID INVALID QUESTION. THEY JUST MAKE THE INTERVIEW HARD SO THAT PEOPLE WHO GOT OFFERS WILL WANT TO ACCEPT IT...TO INCREASE THEIR PATHETIC ACCEPTANCE RATE.

- Anonymous May 27, 2010 | 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