Bloomberg LP Interview Question for Financial Software Developers






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

#include <stdio .h>

void sub(int *a) {
	int b;

	if (&b > a) {
		printf("Stack grows up.");
	} else {
		printf("Stack grows down.");
	}
}

main () {
	int a;
	sub(&a);

}

- Anonymous June 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Need to note that if you define two integers in main() and print their addresses out, you may think it could give you some idea that how stack grows but actually it can't, cauz that program may be optimized by the compiler so that the definition order may not be the execution order. You just cannot trust the result.

- Victor September 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i was searching why people never did that .. this seems to be a good reason :) .. anyone has any other opinion

- Anonymous August 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

will checking addresses of two consecutive elements of an array work?

- Abhijeet July 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

one can easily determine the stack direction by declaring one integer in main and other one in a function , called in main.

As far as "which is Better? " question is considered, I don't think it really matters....They both are good as they both move towards center of memory allocated....

- PatrĂ³n April 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Stack growing UP is better to avoid stack overflow issues. If stack grows down, and you use insecure input function like strcpy, scanf and others.. malicious users can input large string and that would overflow the buffer. Since in C there is no bounds checking, it can result in overwriting of the EBP and the saved EIP. This can happen only if stack grows down. If it grows up, the overflow occurs in yet to be written area of the stack.

- shark January 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

In that the EIP and EBP can be overwritten by changing the parameters passed.But yes changing the local variables won't lead to this.

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

here s what i did..
main(){
int a;
printf("addr of main=%u",main);
printf("addr of a=%u",&a);
sub();
}
sub(){
int b;
printf("addr of sub=%u",sub);
printf("addr of b=%u",&b);
}

..in the result i got addr of main < addr of sub .. but addr of a > addr of b..
Could anyone explain this or where im wrong ??
Thanks in advance.

- gggauravr October 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

may be because the main() is stored in the text segment. And usually text segment is below the Stack segment in the process memory map.

- BJ October 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can call some function. Optimizer cannot change call's stack frame.
Something like that:

int* foo()
{
int a;

return &a;
}

bool bar()
{
int b;
int* pa = foo();

return pa > &b;
}

- ridercoder November 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

but i will also like to add
The expression (&b > a) is undefined.

The result of comparing two pointers using is defined only if the two pointers point to elements within the same array or structure.

The standard says nothing about the direction of the stack or if a stack even exists.

- ridercoder November 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

head or tail [up or down] doesn't effect a stack implemented by Single or Double linked list.
Front or Back effects a stack implemented by Array. Front is less efficient.

- Karthik December 14, 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