Bloomberg LP Interview Question for Financial Software Developers






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

I was asked the same questions and what I did was to declare 2 variables and print out the address of both and compare as done by Neo, but the interviewer said that there were some times when this approach would not be correct and so I wrote another method which he approved, I declared a variable and assigned a pointer which would hold the address of it, in the next line would call a function and pass that pointer value to it, declare a variable there and compare the address of the new variable and the passed value and thus come to know whether the stack is growing upwards or downwards....

please comment on the solution...

- Nishit September 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The order in which the variables withing a function is arranges is compiler dependent. They could be EBP+ or EBP-. So this is not a great indicator. But address of variables from different call levels are very reliable.

- Swamy October 12, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you elaborate on that?

- Anonymous July 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

template<typename T>
bool isGrowingUp(stack<T>& s) {
    T tmp;
    s.push(tmp);
    T *ptr = &s.top();
    s.push(tmp);
    bool up = (++ptr == &s.top());
    s.pop();
    s.pop();
    return up;
}

- Anonymous July 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Generic Method? LOL.

- LOLer July 27, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Make it two :-)

- G November 01, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a,b;
if(&a>&b)
cout<<"downward";
else
cout<<"upward";

- Neo July 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How is this any different than the previous solution? - If the compiler decides to store all local variables in registers and not use the stack at all.

- Girish September 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

to Nishit,

Why don't you turn your idea into code rather than text....

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

@Nishit, is the following correct then ?

#include <stdio.h>
#include <stdlib.h>

void stackFn(int *var1)
{
  int var2;
  
  printf("\n Address of first var  = %u ", var1);
  printf("\n Address of second var = %u ", &var2);

  if(var1 > &var2)
    printf("\n Stack is growing downwards.\n");

  else
    printf("\n Stack is growing upwards.\n");
  
} 

void main()
{
  int var1;

  stackFn(&var1);  

}

- Rajika Tandon November 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

stack<int> T;
bool isStackGrowing()
{
static int *ptr = NULL;
if(ptr == NULL)
{
if(T.size() > 0)
{
ptr = &T.top();
return true;
}
else
return false;
}
bool b = ptr < &T.top();
ptr = &T.top();
return (b);

}

T.push(20);
T.push(21);


cout<<"isStackGrowing: "<<isStackGrowing()<<endl;
T.pop();
cout<<"isStackGrowing: "<<isStackGrowing()<<endl;

- Brahmananda Reddy December 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stack space means not to check the addresses of stuff inside a local stack data structure. Stack space means the space used for a function call. Comparing pointers will work and is a good method.

- Helper December 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bravo Brahmananda Reddy ...u shud apply to google..they will surely accept u

- NC-State January 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Stupid question. Even more stupid answers.

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

Keyword:
Print the address of a local variable
Recursion

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

void foo(char *a);

main()
{
char str=' ';
char *a=&str;
foo(a);
}

void foo(char *a)
{
char str=' ';
char *b=&str;
if(a>b)
printf("down");
else
printf("grow");
}

- Anonymous July 08, 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